Is there a way in your routes file to check and validate URL parameters. I am NOT talking about restful '/controller/action/:id' params, but 'controller/action?param1=x¶m2=y¶m3=z'. I need to be able to validate each parameter and require them.
Yes, you can. For example to check that param1 exists and is not blank you would do the following:
match 'c/action' => 'c#action', :constraints => lambda{ |req| !req.params[:param1].blank? }
You can also scope these constraints to apply them to multiple routes:
scope :constraints => lambda{ |req| !req.params[:param1].blank? } do
match 'controller/action1' => 'controller#action1'
match 'controller/action2' => 'controller#action2'
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With