You can define instance variables for multiple actions by using a before filter, e.g.:
class FooController < ApplicationController
before_filter :common_content, :only => [:index, :show]
def common_content
@some_instance_variable = :foo
end
end
Now @some_instance_variable
will be accessible from all templates (including partials) rendered from the index
or show
actions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…