Rails: Accessing helper methods from a controller

Posted About 1 year ago. Visible to the public.

In Rails 5+ you can access a helper from a controller using the helpers method:

# Inside a controller action
helpers.link_to 'Foo', foo_path

In older Rails versions you can use view_context instead:

# Inside a controller action
view_context.link_to 'Foo', foo_path
Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2023-02-15 09:21)