Ric*_*ick 12 ruby-on-rails case switch-statement
我有一部分只有在某些页面使用该布局时我才想在布局中显示.我为所有页面设置了@page_title,并认为我可以使用这样的东西:
<% case @page_title when "Log in" || "Forgot Your Password" || "Create a New Password" %><%= render :partial => "common/hello-world" -%><% end -%>
Run Code Online (Sandbox Code Playgroud)
但是,包含仅发生在标题为"登录"的页面上,而不是其他页面.是|| Case开关上不允许这样的语句?是否有不同的方法在案例开关中设置OR语句?
谢谢!
Aar*_* Fi 22
这就是你想要的:
<% case @page_title when "Log in", "Forgot Your Password", "Create a New Password" %><%= render :partial => "common/hello-world" -%><% end -%>
Run Code Online (Sandbox Code Playgroud)
根据http://docs.huihoo.com/ruby/ruby-man-1.4/syntax.html#case
pts*_*pts 13
之后使用,而不是||分隔匹配when.有关Ruby语法的更多信息,请参见http://docs.huihoo.com/ruby/ruby-man-1.4/syntax.html#case.
| 归档时间: |
|
| 查看次数: |
11974 次 |
| 最近记录: |