arrays - Ruby How to display message if include? statement is true or false -


i'm very new ruby , attempting display 1 of 2 messages based on whether words included in array. current controller contains following:

@cookie = ["gluten", "sugar", "dairy", "chocolate"] 

and view contains this:

<%= @cookie.include?"gluten" %> 

the above returns 'true' , prints on page fine. however, nothing gets printed on page when trying either of following methods. page renders fine no errors, no messages:

<%= puts "sorry" if @cookie.include?"gluten" %> 

and

<%=  if @cookie.include?("gluten")   puts "sorry, cannot eat this."     else   puts "you have greenlight."     end %> 

i'm hoping i'm creating simple mistake in syntax or misunderstanding usage of include? function.

looking @ ruby appears sound, http://rubyfiddle.com/riddles/d6798.

must rails error try

<% if @cookie.include?("gluten") %>   <%= "sorry, cannot eat this." %> <%  else %>   <%= "you have greenlight." %> <%  end %> 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -