使用|| Rails 中的 Case 开关
我有一个部分,仅当某些页面使用该布局时才想在布局中显示。 我已经为所有页面设置了@page_title,并认为我可以使用类似这样的内容:
<% case @page_title when "Log in" || "Forgot Your Password" || "Create a New Password" %><%= render :partial => "common/hello-world" -%><% end -%>
但是,包含仅发生在标题为“登录”的页面上,而不是其他页面上。 是|| Case 开关上不允许这样的语句? 是否有不同的方法在 case 开关中设置 OR 语句?
谢谢!
I have a partial that I want to display in a layout only when certain pages use that layout. I've set @page_title for all my pages and thought I could use something like this:
<% case @page_title when "Log in" || "Forgot Your Password" || "Create a New Password" %><%= render :partial => "common/hello-world" -%><% end -%>
But, the include is only happening on the page titled "Log in" and not the other pages. Are || statements like this not allowed on Case switches? Is there a different way to set an OR statement in the case switch?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是您想要的:
根据 http://docs.huihoo。 com/ruby/ruby-man-1.4/syntax.html#case
This is what you want:
Per http://docs.huihoo.com/ruby/ruby-man-1.4/syntax.html#case
使用
,
而不是||
来分隔when
之后的匹配项。 有关 Ruby 语法的更多信息,请参见 http://docs.huihoo.com /ruby/ruby-man-1.4/syntax.html#case。Use
,
instead of||
to separate the matches afterwhen
. See more about Ruby syntax in http://docs.huihoo.com/ruby/ruby-man-1.4/syntax.html#case.