I understand that rails drops all instance variables created in normal
controller action after rendering view templates.
But I have the following problem that a normal controller action has
several before_filter and after_filter, which all using same set of
variables fetching from database.
#######################################
Class AppSetting< ActionRecrod::Base
end
Class PeopleController < ApplicationController
before_filter :get_title
before_filter :get_subtitle
after_filter :update_some_properties_on_condition
after_filter :update_some_other_properties_on_condition
def index
@name= Person.first.name
end
private
def get_title
@title = AppSetting.first.title
end
def get_subtitle
@subtitle = AppSetting.first.subtitle
end
def update_some_properties_on_condition
do_something if condition1 == AppSetting.first.condition1
end
def update_some_other_properties_on_condition
do_something if condition2 == AppSetting.first.condition2
end
end
#######################################################
As you can see, all the five methods all using “AppSetting.first”
object in the process.
Is there anyway that I can set some variables that all actions can use
in this process? just like the function of class variables in ordinary
ruby code.