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 Build a Simple Ruby on Rails Application Designing URLs Refactoring the Flash Code

Iyad Horani
PLUS
Iyad Horani
Courses Plus Student 6,141 Points

erb code not executing inside the div tag

Hi Guys

Trying to make the helper method working with Rails 4.1.0 and Ruby 2, so far adding anything in the class="<%= method name %>" does not get executed. any thoughts?

<% flash.each do |key, value| %>
  <div class="<%= flash_class(key) %>">
    <%= value %>
  </div>
<% end %>

3 Answers

Iyad Horani
PLUS
Iyad Horani
Courses Plus Student 6,141 Points

Looks like the problem is with the application_helper.rb, for some reason the application.html.erb doesn't have access to it. The code inside application_helper.rb is not running at all! any ideas?

Stone Preston
Stone Preston
42,016 Points

hmm any helper methods inside the application helper should automatically be available in your layout file. are you sure your method is correct? mind posting the method implementation?

Iyad Horani
PLUS
Iyad Horani
Courses Plus Student 6,141 Points

Hi stone,

Thanks for your reply. Here is the method:

module ApplicationHelper
  def flash_class(level)
    case level
    when :notice then "alert alert-info"
    when :success then "alert alert-success"
    when :error then "alert alert-error"
    when :alert then "alert alert-error"
    end
  end
end
Iyad Horani
PLUS
Iyad Horani
Courses Plus Student 6,141 Points

Any other ideas on why this is not working from within the application_helper only? Thanks