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!
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

william kenny
5,428 PointsTroubleshooting Help with Rails and Forms and Alerts
tl,dr: Having problems displaying :alerts correctly, need help finding where the problem is and fixing it.
I am bumbling my way through this: http://teamtreehouse.com/library/programming/build-a-simple-ruby-on-rails-application/designing-urls/refactoring-the-flash-code
and so far, haven't had any serious errors. However, as I'm watching the video I think to myself, maybe I should test that the :alert messages are coming through correctly.
I goto the login page and enter incorrect information, then hit login, but nothing happens. The page refreshes (doesn't let me login) but doesn't seem to display any errors. This is odd as when I login, the :notice displays correctly.
So, I think the :alert message is either not getting generated, or getting lost in a refresh. But how do I track this problem down?
Here is what the console says:
Started POST "/users/sign_in" for 127.0.0.1 at 2013-03-31 16:29:08 +0600
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"?", "authenticity_token"=>"zvVG2p3ksQakqSrFisaVIizMBPbHk
aYfSOaPA89c+lw=", "user"=>{"email"=>"bk@gmail.com", "password"=>"[FILTERED]", "r
emember_me"=>"0"}, "commit"=>"Sign in"}
?[1m?[35mUser Load (0.0ms)?[0m SELECT "users".* FROM "users" WHERE "users"."e
mail" = 'bk@gmail.com' LIMIT 1
Completed 401 Unauthorized in 113ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"?", "authenticity_token"=>"zvVG2p3ksQakqSrFisaVIizMBPbHk
aYfSOaPA89c+lw=", "user"=>{"email"=>"bk@gmail.com", "password"=>"[FILTERED]", "r
emember_me"=>"0"}, "commit"=>"Sign in"}
Rendered devise/shared/_links.erb (0.0ms)
Rendered devise/sessions/new.html.erb within layouts/application (7.0ms)
Completed 200 OK in 97ms (Views: 16.0ms | ActiveRecord: 0.0ms)
ps, i'm trying to display the console output in code form but it doesn't seem to work. I did the 4 space indent, but didn't seem to have an effect.
Help?
14 Answers

william kenny
5,428 Pointsps, as a follow up for any fruitful searches, here is the answer:
I had this:
<% if flash[:notice] %>
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">x</button>
<%= flash[:notice] %>
</div>
<% end %>
It should be this:
<% flash.each do |type, message| %>
<div class="alert <%= flash_class type %>" >
<button type="button" class="close" data-dismiss="alert">x</button>
<%= message %>
</div>
<% end %>

Jason Seifer
Treehouse Guest TeacherCan you paste your app/views/layouts/application.html.erb file?

Derek Saunders
5,167 PointsHi Jason, I'm having troubles with this I have everything exactly as Jim and everyone else on this forum, but yet I still get a syntax error.

william kenny
5,428 Pointsfor that smile, always:
<!DOCTYPE html>
<html>
<head>
<title>Treebook</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div class = "navbar navbar-fixed-top">
<div class = "navbar-inner">
<div class = "container">
<a href = "#" class = "brand"> Treebook</a>
<ul class = "nav">
<li><%= link_to "All Satuses", statuses_path %></li>
</ul>
<ul class="nav pull-right">
<% if user_signed_in? %>
<li><%= link_to current_user.full_name, edit_user_registration_path %></li>
<li><%= link_to "Log Out", destroy_user_session_path, method: :delete %></li>
<% else %>
<li><%= link_to "Register", new_user_registration_path %></li>
<li><%= link_to "Log In", new_user_session_path %></li>
<% end %>
</ul>
</div>
</div>
</div>
<div class="container">
<% flash.each do |type, message| %>
<div class="alert <%= flash_class type %>" >
<button type="button" class="close" data-dismiss="alert">x</button>
<%= message %>
</div>
<% end %>
<%= yield %>
</div>
</body>
</html>

Jason Seifer
Treehouse Guest TeacherWilliam, I'd like to troubleshoot your code on this one. Can you possibly email it to help@teamtreehouse.com?

william kenny
5,428 Pointsemail sent! I just 7zipped the whole directory and sent it.
Thanks again for all the help!!

william kenny
5,428 PointsThat fixed the error. note to self, save in sublime otherwise your changes won't actually be changes!!

Itay Banner
1,922 PointsArrrrrrgh. I keep omitting the equal sign so I'm getting all these errors and bugs. But I've only myself to blame, I guess :-0

Brandon Rodgers
1,219 PointsSame here. I didn't even think to check until reading your response. Thanks! :)

Derek Saunders
5,167 PointsI have the same exact thing typed in and it gives me an error when I refresh my browser, it gives me a syntax error even though it is exactly what Jim typed in. I'm a little confused.

william kenny
5,428 PointsFirst, make sure that when you edit the file you save the file. I had that problem with sublime and it caused me lots of troubles.
Snytax errors are usually related to dropped closers or something like that. If your code references a line (it's been a while since i've messed with Ruby) can you post the code around that line?

Derek Saunders
5,167 Pointsthe only problem is that it doesn't reference a line

Jason Seifer
Treehouse Guest TeacherWhat does it say Derek Saunders?

Derek Saunders
5,167 Pointswilliam kenny I figured it out, in the application_helper.rb I just realized I forgot to end the def flash_class(type) I didn't realize it needed three end tags.

Derek Saunders
5,167 PointsJason Seifer thank you for asking! I figured it out just now haha. :)

william kenny
5,428 PointsNot a problem. That stuff drives me CRAZY! I can't tell you how many hours I've spent in other languages looking for the one line that I forgot to add a ;
Ian Warner
5,563 PointsIan Warner
5,563 PointsThanks for posting this! This helped fixed my error. I really appreciate it. :)