Checking multiple conditions in Ruby (within Rails, which may not matter)
- by Ev
Hello rubyists and railers,
I have a method which checks over a params hash to make sure that it contains certain keys, and to make sure that certain values are set within a certain range. This is for an action that responds to a POST query by an iPhone app.
Anyway, this method is checking for about 10 different conditions - any of which will result in an HTTP error being returned (I'm still considering this, but possibly a 400: bad request error).
My current syntax is basically this (paraphrased):
def invalid_submission_params?(params)
[check one] or
[check two] or
[check three] or
[check four] etc etc
end
Where each of the check statements returns true if that particular parameter check results in an invalid parameter set. I call it as a before filter with params[:submission] as the argument.
This seems a little ugly (all the strung together or statements). Is there a better way? I have tried using case but can't see a way to make it more elegant.
Or, perhaps, is there a rails method that lets me check the incoming params hash for certain conditions before handing control off to my action method?