Amazing! It's finally fully working logging in and out and holding onto the cookies, thank you so much for all your help! 
Just for those that find this post and are interested the final solution from scannon was as follows.
Sessions Controller
Code:
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
if params[:remember_me]
cookies.permanent[:auth_token] = user.auth_token
else
cookies[:auth_token] = user.auth_token
end
redirect_to root_url
else
flash.now.alert = "Invalid email or password!"
render "signup"
end
end
def destroy
cookies.delete(:auth_token)
redirect_to root_url
end
end
Application controller
Code:
class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :current_user
private
def current_user
@current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
end
end
User Model
Code:
class User < ActiveRecord::Base
has_secure_password
before_create { generate_token(:auth_token) }
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_length_of :email, :within => 6..50
validates_length_of :password, :within => 6..30
validates_uniqueness_of :email, :case_sensitive => false, :on => :create
validates_format_of :email, :with => /^[A-Z0-9_.%-]+@([A-Z0-9_]+\.)+[A-Z]{2,4}$/i,
:message => "must be a valid e-mail address"
def generate_token(column)
begin
self[column] = SecureRandom.urlsafe_base64
end while User.exists?(column => self[column])
end
end
User new
Code:
<div id="signup-area">
<h1>Sign Up</h1>
<div class="signup-fields">
<%= form_for @user do |f| %>
<% if @user.errors.any? %>
<div class="error_messages">
<h2>Form is invalid</h2>
<ul>
<% for message in @user.errors.full_messages %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class = "field">
<%= f.label :email %>
<%= f.text_field :email %>
</div>
<div class = "field">
<%= f.label :password %>
<%= f.password_field :password %>
</div>
<div class = "field">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
</div>
<div class="actions"><%= f.submit "Submit" %></div>
</div>
<% end %>
</div>
Sessions New
Code:
<div id="login-area">
<div id="title">
<h1>Log In</h1>
</div>
<%= form_tag login_path do %>
<div class="login-fields">
<div class="field">
<%= label_tag :email %>
<%= text_field_tag :email, params[:email] %>
</div>
<div class ="field">
<%= label_tag :password %>
<%= password_field_tag :password %>
</div>
<div class="actions"><%= submit_tag "Log in" %></div>
</div>
<%end%>
<div class = "field">
<%= label_tag :remember_me %>
<%= check_box_tag :remember_me, 1, params[:remember_me] %>
</div>
<div class="Not-registered">
<p>Not yet registered? <%= link_to "Sign up here", signup_path %></p>
</div>
</div>
Pages#Home login and logout element
Code:
<div class="login">
<% if current_user %>
Hi, <%= current_user.email %>! <br />
<%= link_to "Logout", logout_path %>
<% else %> <%= link_to "Login", login_path %> or <%= link_to "Sign up", signup_path %>
<% end %>
</div>
Thanks again scannon for some amazing help!
Tom
Bookmarks