Rails: Do something once per page reload -


how invoke method once per page reload? defining before_filter in applicationcontroller failed because of multiple controllers used perform action

when multiple controllers used in 1 action, more specific? before_filter in controller responsible action suffice.

if want before filter affect specific methods in multiple controllers place method in applicationcontroller before_filter in each of controllers contain action.

class applicationcontroller   def foo     @bar = 'bar'   end end  class usercontroller   before_filter :foo, :only => [:method1]      def method1     ...   end    def method2     ...   end end  class stuffcontroller   before_filter :foo, :only => [:method2]      def method1     ...   end    def method2     ...   end end    class unimportantcontroller   # no before filter, neither of these methods call :foo    def method1     ...   end    def method2     ...   end end 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -