ato*_*nyc 11 haml ruby-on-rails
我的问题是我正在尝试做类似的事情
current_page?(controller: 'tigers', action:('index'||'new'||'edit'))
Run Code Online (Sandbox Code Playgroud)
当控制器是老虎并且操作是索引,新建或编辑时,它返回true.
以上内容不会引发错误,只会匹配第一个操作.
救命!
sbe*_*ker 15
更详细,但有效:
current_page?(controller:'bikes') &&
(current_page?(action:'index') ||
current_page?(action:'new') ||
current_page?(action:'edit'))
Run Code Online (Sandbox Code Playgroud)
不那么冗长,也有效:
params[:controller] == 'bikes' && %w(index new edit).include?(params[:action])
Run Code Online (Sandbox Code Playgroud)
%w()是构建空格分隔字符串数组的快捷方式
你也可以做这样的事情:
if current_page?(root_path) || current_page?(about_path) || current_page?(contact_path) || current_page?(faq_path) || current_page?(privacy_path)
Run Code Online (Sandbox Code Playgroud)
注意:括号前不要留空格,否则无效。
| 归档时间: |
|
| 查看次数: |
8989 次 |
| 最近记录: |