-1

Is there a field or method I can lookup within an .html.erb file that will tell me the current action used to render the page? This code would be in a partial. I'm looking for something like this:

<% if @action == :new %>
  this is new
<% end %>
4

2 回答 2

3

是的,你有action_name并且controller_name为此目的。

但请注意:结果是一个字符串,而不是一个符号。

说明

于 2012-11-27T20:54:16.810 回答
0

你可以做这样的事情。

<% if params[:action] ==  "new" %>
  # do something here
<% end %>
于 2012-11-27T23:38:39.427 回答