Rails: method defined in application_helper.rb not recognized by categories_controller.rb
ruby-on-rails
Solution
Helpers are not included into a controller by default. You can
include ApplicationHelper
To gain access to the methods in the ApplicationHelper module. The previous discussion has a bunch of useful solutions for accessing helpers in controller.
Problem
More newbie issues. I understand that if I define a method in my application helper, it is available to the entire app code. In my applicaton helper, I have: ``` def primary_user_is_admin if current_user user_login_roles = JSON.parse(current_user.role) if user_login_roles["admin"] return 1 end end return nil end ``` If I call it from the categories_controller: ``` if !primary_user_is_admin redirect_to root_url end ``` I get an error message: undefined local variable or method `primary_user_is_admin' This also happens if I put the primary_user_is_admin code in the registrations_helper.rb file However, if I use it in any of the views (views/user/edit.html.erb for instance) ``` <% if primary_user_is_admin %> <% end > ``` then it works. What am I missing?