-1
  • If there is a flash notice > "Flash notice"
  • If there isn't a flash notice and you're on the homepage > "Welcome"

Code:

<% if flash %>
  <% flash.each do |name, msg| %>
    <%= content_tag :span, msg, id: "flash_#{name}" %>
  <% end %>
<% elsif current_page('/') %>
  <% print 'Hi' %>
<% end %>

It prints the flashes correctly but not the welcome on the home page. Doesn't seem to matter if I try current_page or root_url or print 'Welcome' or just plain "Welcome" with no code wrapper. Why?

Matthew Bennett
  • 303
  • 2
  • 12
  • 2
    The `elsif` check will only occur when `flash` is "falsey" - what is the value of `flash` when you're expecting the `eslif` check to happen? – frostmatthew Aug 16 '15 at 12:17
  • 2
    I suspect that `flash` is merely an empty hash rather than false or nil (which are Ruby's only "falsy" values). That is, `if {}` is actually `true`. – Michael Berkowski Aug 16 '15 at 12:17
  • 1
    See [A concise explanation of nil vs blank vs empty in Rails](http://stackoverflow.com/questions/885414/a-concise-explanation-of-nil-v-empty-v-blank-in-ruby-on-rails) – Michael Berkowski Aug 16 '15 at 12:19

1 Answers1

0

Yes, almost, I wasn't checking the flash properly at the beginning of the block. This works now:

<% if flash.present? %>
  <% flash.each do |name, msg| %>
    <%= content_tag :span, msg, id: "flash_#{name}" %>
  <% end %>
<% elsif current_page?('/') %>
  Welcome to The Spain Report.
<% end %>

Thank you all!

Matthew Bennett
  • 303
  • 2
  • 12