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

william kenny
william kenny
5,428 Points

Troubleshooting 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
william kenny
5,428 Points

ps, 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 %>

Thanks for posting this! This helped fixed my error. I really appreciate it. :)

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Can you paste your app/views/layouts/application.html.erb file?

Derek Saunders
Derek Saunders
5,167 Points

Hi 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
william kenny
5,428 Points

for 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
STAFF
Jason Seifer
Treehouse Guest Teacher

William, I'd like to troubleshoot your code on this one. Can you possibly email it to help@teamtreehouse.com?

william kenny
william kenny
5,428 Points

email sent! I just 7zipped the whole directory and sent it.

Thanks again for all the help!!

william kenny
william kenny
5,428 Points

That fixed the error. note to self, save in sublime otherwise your changes won't actually be changes!!

Itay Banner
Itay Banner
1,922 Points

Arrrrrrgh. 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
Brandon Rodgers
1,219 Points

Same here. I didn't even think to check until reading your response. Thanks! :)

Derek Saunders
Derek Saunders
5,167 Points

I 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
william kenny
5,428 Points

First, 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
Derek Saunders
5,167 Points

the only problem is that it doesn't reference a line

Derek Saunders
Derek Saunders
5,167 Points

william 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
Derek Saunders
5,167 Points

Jason Seifer thank you for asking! I figured it out just now haha. :)

william kenny
william kenny
5,428 Points

Not 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 ;