I'm doing an app with session management and I want to display if the user is logged in or not at the top of every page. I have the front-end for this in application.rhtml.erb, is there any controller/method that will let me set a site-wide variable? As it is I define the condition for every individual page, there has to be a better way.
1 Answer
Put your method in the application_helper.rb file. That'll be available site-wide.
1 Comment
Tom Harrison
application_helper.rb will only affect views, I believe. I think you want to add code to application_controller.rb if you want it to be available from all other controller. If you also want it to be available in views, add a line after the method definition helper :my_method. See a good post on this here: stackoverflow.com/questions/3549713/controller-helper-method