This has to be simple but I am not able to figure it out.
I only want the :notice data (and <p> tags) to show up in the
application layout if there is a notice.
The code below works if there is not a :notice (nothing shows up in
code) but gives an error if there is a notice. The error is "undefined
method `exists?'".
<% if flash[:notice] :exists? %>
<p><%= flash[:notice] %></p>
<% end %>
Hey Sunny,
Just to anwser your questions.
exists? is not a method, hence your error.
What you'll want to do is something like
<%= flash[:notice] if flash[:notice] %>
Which is basically Ruby short hand for
<% if flash[:notice] %>
<%= flash[:notice] %>
<% end %>
You don't need an exists? method Ruby implies it already, as does
javascript for instance. You could also use
<%= flash[:notice] unless flash[:notice].blank? %>
As blank? is a method that checks for the presence of nil