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

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -