使用|| Rails中的Case开关 [英] Using || in Case switch in Rails

查看:89
本文介绍了使用|| Rails中的Case开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有部分页面使用该布局时,我才想在该布局中显示它.我已经为所有页面设置了@page_title,并认为我可以使用类似这样的东西:

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 -%>

但是,包含仅在标题为登录"的页面上发生,而不在其他页面上发生.是|| Case开关上不允许这样的语句?在大小写转换中是否有其他方法可以设置OR语句?

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?

谢谢!

推荐答案

这就是您想要的:

<% 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

这篇关于使用|| Rails中的Case开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆