How do I call a method in application helper from a view? How do I call a method in application helper from a view? ruby-on-rails ruby-on-rails

How do I call a method in application helper from a view?


not sure what is the issue, but you can solve this by include the application_helper in the controller

class TrunksController     include ApplicationHelperend

In the view call:

<%= @controller.rxtrnk %>


You should make sure that the helper containing the method you want to call is included by the current controller (in your case you want to include the ApplicationHelper). This is controlled using the "helper" method in top of controllers.

Many Rails developers just include all helpers by default to avoid having to think about this. To do this add "helper :all" to the top of your ApplicationController:

class ApplicationController < ActionController::Base  helper :allend

You can also choose to only include the ApplicationHelper:

class ApplicationController < ActionController::Base  helper ApplicationHelperend


your TrunksController might not be extending from the ApplicationController. The application Controller includes the Application helper so if you extend your controller form it, you should have access to those methods.

The start of your controller should be something like:

class TrunksController < ApplicationController