Use conditions in before-filters System-file-manager controller - suggested by Soleone, 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 method html_request returns true.

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):

Applications-internet Go here for additional information: http://giantrobots.thoughtbot.com/2008/2/15/when-rails-plugin


0 Comments

Title (optional)

Text (Textile is active)


Back to all Tips