使用|| Rails 中的 Case 开关

发布于 2024-07-19 01:16:18 字数 380 浏览 4 评论 0原文

我有一个部分,仅当某些页面使用该布局时才想在布局中显示。 我已经为所有页面设置了@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

杯别 2024-07-26 01:16:18

这就是您想要的:

<% case @page_title when "Log in", "Forgot Your Password", "Create a New Password" %><%= render :partial => "common/hello-world" -%><% end -%>

根据 http://docs.huihoo。 com/ruby/ruby-man-1.4/syntax.html#case

This is what you want:

<% case @page_title when "Log in", "Forgot Your Password", "Create a New Password" %><%= render :partial => "common/hello-world" -%><% end -%>

Per http://docs.huihoo.com/ruby/ruby-man-1.4/syntax.html#case

会傲 2024-07-26 01:16:18

使用 , 而不是 || 来分隔 when 之后的匹配项。 有关 Ruby 语法的更多信息,请参见 http://docs.huihoo.com /ruby/ruby-man-1.4/syntax.html#case

Use , instead of || to separate the matches after when. See more about Ruby syntax in http://docs.huihoo.com/ruby/ruby-man-1.4/syntax.html#case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文