Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

alborz
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Points

Regarding setup step #3 for Devise gem

Hi - I'm wondering about this step when setting up the Devise gem.

It says to:

Ensure you have flash messages in app/views/layouts/application.html.erb. For example:

   <p class="notice"><%= notice %></p>
   <p class="alert"><%= alert %></p>

So would I just use the above in application.html.erb? I'm asking this because as I'm going through Mackenzie Child's tutorial on how to build a Reddit clone https://mackenziechild.me/12-in-12/1/ he mentions when going through this step to do:

<% flash.each do |name, msg| %>
<%= content_tag(:div, msg, class: "alert alert-#{name}") %>
<% end %>

So I'm not sure.

Could someone please explain this and how I would go about implementing it? Thanks!

1 Answer

Though it doesn't look like it, they are talking about the same thing.

flash is a hash of 1) type and 2) message

Examples:

flash[:success] = "Well Done"
flash[:error] = "Unable to connect"
flash[:notice] = "Please try again"
  • notice/notice() is a function that is a shortcut to flash[:notice]
  • alert/alert() is a function that is a shortcut to flash[:alert]

The second option that iterates through the flash hash is the more flexible way to display the flash messages.