开发者

In a application controller filter, do I know which action is going be called?

开发者 https://www.devze.com 2023-01-28 10:19 出处:网络
say in my application controller, I have a before_filter that gets fired, loads some @instance_variables that I will use in my application layout file.

say in my application controller, I have a before_filter that gets fired, loads some @instance_variables that I will use in my application layout file.

is it possible to load data based on the action that will be re开发者_如何转开发ndered? If yes, how can I figure out the action that is about to be called?


You could either split them up in separate filters.

before_filter :task_show_index, :only => [:index, :show]
before_filter :task_create, :only => :create

or you could read from params

case params[:action]
  when "show"
    # Do something
  when "create"
    #Do something else
end
0

精彩评论

暂无评论...
验证码 换一张
取 消