Ruby on Rails Tip: Using Controller Methods in Views 0

Suppose you have a method in a controller that you want to use in a view. If you try to just invoke it as a helper, you’ll get a method not found error, because controller methods are out of scope for views.

You can, however, make any method available as a helper by simply declaring it as such in the controller:


helper_method :some_method_name, :another_method_name

The method must be in the same controller as the one that invoked the view.

Comment



If you're reading this message, your browser is not interpreting the CSS file properly, and your comment may not be posted.