def validate_input(*parameters)
if parameters.any?(&:nil?)
render :json => { :error => 'Please fix some params' }
false
else
true
end
end
def action
...
return unless validate_input(my_sane_id, my_other_param)
...
end
you can use the splat operator ("*") to get unknown number of parameters into array
you can use ("any?") method instead of index (which is location)
you can use symbol to proc ("&:") if you only making the function call on each item in array
you dont need to call to_json if you render json
better use symbol as hash key (":error")
you return true/false to indicate if everything ok, and if its false, just return from the action