Authenticating user

Now we can add the registraiton and login link to the view.

The header tag in layout/application.html.erb file becomes:

 1<header class='row'>
 2  <div class='full col'>
 3    <nav>
 4      <ul>
 5        <li><%= link_to 'Home', root_path %></li>
 6        <% if user_signed_in? %>
 7          <li><%= link_to "Logout (#{})", destroy_user_session_path, :method => :delete %></li>
 8        <% else %>
 9          <li><%= link_to 'Login', new_user_session_path  %></li>
10          <li><%= link_to 'Sign Up', new_user_registration_path  %></li>
11        <% end %>
12      </ul>
13    </nav>
14  </div>

Now we have the sign up page linked from the top nav.

Gallery sign up page

Also in the views/pages/index.html.erb file, we want to either link to the new album page or new registraiton page base on the current user session.

1<% if user_signed_in? %>
2  <p><%= link_to 'Create Album', new_album_path %></p>
3<% else %>
4  <p><%= link_to 'Register Now', new_user_registration_path %></p>
5<% end %>

The index page when logged out.

Gallery logged in page

And the index page when logged in. Note the “login” and “logout” between these two images.

Gallery logged out page

What’s next? We’re going to take a look at “Protecting upload”.

overlaied image when clicked on thumbnail

Makzan | Ruby on rails 101 | Table of Content