Rails: Scope: making a method available to all Views and Controllers -
i've struggled scope few days. have small number of methods available views , controllers. suppose code is:
def login_role if current_user return current_user.role end return nil end
if include in application_helper.rb, it's available views, not available controllers
if include in application_controller.rb, it's available controllers, not available views.
use helper_method
method in applicationcontroller
give views access.
class applicationcontroller < actioncontroller::base helper_method :login_role def login_role current_user ? current_user.role : nil end end
consider putting related methods in own module may make them available this:
helper loginmethods
Comments
Post a Comment