Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using || in Case switch in Rails

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!

like image 858
Rick Avatar asked May 08 '09 20:05

Rick


2 Answers

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

like image 50
Aaron Fi Avatar answered Oct 11 '22 12:10

Aaron Fi


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.

like image 39
pts Avatar answered Oct 11 '22 12:10

pts