Use conditions in before-filters
controller
3 months ago
If you want to execute a certain piece of code before a controller action gets called, you can use the before_filter-method, that should be
common knowledge.
But did you know that since Rails 2.0.2 you can also add conditions to the filter?
This will execute the
my_debug-method only when the methodhtml_requestreturnstrue.
This feature was first available from the When-Plugin, but is now included in the core!
There is also a shorter version, where you can specify the condition with an anonymous function (lambda):
Go here for additional information: http://giantrobots.thoughtbot.com/2008/2/15/when-rails-plugin
Back to all Tips

0 Comments