I have some troubles with routes in Rails 4 (rusty Rails user). I have the following routes for my Session controller:
controller :sessions do
get 'login' => :new
post 'login' => :create
delete 'logout' => :destroy
end
get "sessions/create"
get "sessions/destroy"
And I have a form that looks like this:
= form_tag do
.form_container
.field
= label_tag :name, "Namn:"
= text_field_tag :name, params[:name]
.field
= label_tag :password, "Lösenord:"
= password_field_tag :password, params[:password]
.actions
= submit_tag 'Login', :class => "submit_button"
And my session#create action looks like this:
def create
user = User.find_by(name: params[:name])
if user and user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to root_path
else
redirect_to login_url, alert: "Invalid user/password combination"
end
end
And I get the following error:
No route matches [POST] "/login/create"
How should my routes look in this case?
I generally have a
resource :session
post 'login' => 'sessions#create'
get 'login' => 'sessions#new'
that creates
session POST /session(.:format) sessions#create
new_session GET /session/new(.:format) sessions#new
edit_session GET /session/edit(.:format) sessions#edit
GET /session(.:format) sessions#show
PUT /session(.:format) sessions#update
DELETE /session(.:format) sessions#destroy
login POST /login(.:format) sessions#create
GET /login(.:format) sessions#new
And after that just use the correct urls where needed
= form_tag login_path
...
That should do the trick
Related
I am following along this tutorial's authentication process - currently on the section 'User Authentication':
http://larsgebhardt.de/user-authentication-with-ruby-on-rails-rspec-and-capybara/
I received the follower test failure:
1) User Management User log in
Failure/Error: login(#writer)
ActionController::RoutingError:
uninitialized constant SessionController
# ./spec/support/user_helper.rb:6:in `login'
# ./spec/features/users_spec.rb:27:in `block (2 levels) in <top (required)>'
Here is the specific test and helper file mention in the failure message, along with other files..
spec/features/users_spec.rb
require 'spec_helper'
background do
#writer = create(:user, :writer)
end
....
scenario 'User log in' do
activate(#writer)
login(#writer)
expect(page).to have_content "Successfully logged in."
end
spec/support/user_helper.rb
module UserHelper
def login(a)
visit root_path
click_link 'Log In'
fill_in 'session[email]', with: a.email
fill_in 'session[password]', with: a.password
click_button 'Log In'
end
def logout(a)
visit root_path
click_link 'Log Out'
end
def activate(a)
visit activate_path(:code => a.activation_code)
end
end
routes.rb
resources :session
sessions_controller.rb
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by_email(params[:session][:email]).try(:authenticate, params[:session][:password])
if user
if user.is_active?
session[:user_id] = user.id
redirect_to (session[:target_url] || root_path)
flash[:notice] = "Successfully logged in."
else
redirect_to new_session_path
flash[:error] = "Account inactive. Please activate your account."
end
else
redirect_to new_session_path
flash[:error] = "Invalid email or password."
end
end
def destroy
session[:user_id] = nil
redirect_to root_path
flash[:notice] = "Successfully logged out."
end
end
new.html.erb
<h1>Log In</h1>
<%= form_for :session, url: sessions_path do |f| %>
<div>
<%= f.label :email %>
<%= f.text_field :email %>
</div>
<div>
<%= f.label :password %>
<%= f.password_field :password %>
</div>
<div>
<%= f.submit 'Log In' %>
</div>
<% end %>
rake routes
Prefix Verb URI Pattern Controller#Action
profiles_show GET /profiles/show(.:format) profiles#show
sessions_new GET /sessions/new(.:format) sessions#new
users_new GET /users/new(.:format) users#new
root GET / sessions#new
post_comments GET /posts/:post_id/comments(.:format) comments#index
POST /posts/:post_id/comments(.:format) comments#create
new_post_comment GET /posts/:post_id/comments/new(.:format) comments#new
edit_post_comment GET /posts/:post_id/comments/:id/edit(.:format) comments#edit
post_comment GET /posts/:post_id/comments/:id(.:format) comments#show
PATCH /posts/:post_id/comments/:id(.:format) comments#update
PUT /posts/:post_id/comments/:id(.:format) comments#update
DELETE /posts/:post_id/comments/:id(.:format) comments#destroy
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
sessions GET /sessions(.:format) sessions#index
POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
edit_session GET /sessions/:id/edit(.:format) sessions#edit
session GET /sessions/:id(.:format) sessions#show
PATCH /sessions/:id(.:format) sessions#update
PUT /sessions/:id(.:format) sessions#update
DELETE /sessions/:id(.:format) sessions#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
profile_index GET /profile(.:format) profile#index
POST /profile(.:format) profile#create
new_profile GET /profile/new(.:format) profile#new
edit_profile GET /profile/:id/edit(.:format) profile#edit
profile GET /profile/:id(.:format) profile#show
PATCH /profile/:id(.:format) profile#update
PUT /profile/:id(.:format) profile#update
DELETE /profile/:id(.:format) profile#destroy
activate GET /activate/:code(.:format) users#activate
_header.html.erb
About
Services
<%= link_to "Sign Up", new_user_path %>
<%= link_to "Log In", new_session_path %>
<%= link_to "Log Out", "/session", method: :delete %>
I previously had an issue with configuring the User Helper file which was solved but incase it becomes relevant, you can see the answer and state of the config file here:
Rspec email_spec issue
You need resources :sessions, you are missing the 's'.
Edit :
You are using the delete route incorrectly, you should say
<%= link_to "Log Out",session_path(pass the current signed in user here) , method: :delete %>
When I submit this form
<h1>Log In</h1>
<%= simple_form_for sessions_path do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :remember_me, as: :boolean %>
<%= f.submit 'Log In' %>
<% end %>
It gives me this error: No route matches [POST] "/login". It is true that I don't have a route that matches that, but from what I understand, it should be POSTing to sessions#create, for which I have a route and an action. Why is it not doing this?
routes.rb
DinnerDash::Application.routes.draw do
get 'login', to: 'sessions#new', as: 'login'
get 'logout', to: 'sessions#destroy', as: 'logout'
get 'signup', to: 'users#new', as: 'signup'
root 'items#index'
resources :users
resources :password_resets
resources :sessions
resources :items
get "password/Resets"
get "password/create"
get "password/edit"
get "password/update"
end
sessions_controller.rb
class SessionsController < ApplicationController
def new
end
def create
user = login(params[:email], params[:password], params[:remember_me])
if user
redirect_back_or_to root_url, notice: 'Logged in!'
else
flash.now.alert = 'Unable to login.'
render :new
end
end
def destroy
logout
redirect_to root_url, notice: 'Logged out.'
end
end
rake routes
It's sorta hard to read, but the important points are that there's a GET /login, not a POST /login, and there's a GET and POST for /sessions_path.
login_path GET /login(.:format) sessions#new
logout_path GET /logout(.:format) sessions#destroy
signup_path GET /signup(.:format) users#new
root_path GET / items#index
users_path GET /users(.:format) users#index
POST /users(.:format) users#create
new_user_path GET /users/new(.:format) users#new
edit_user_path GET /users/:id/edit(.:format) users#edit
user_path GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
password_resets_path GET /password_resets(.:format) password_resets#index
POST /password_resets(.:format) password_resets#create
new_password_reset_path GET /password_resets/new(.:format) password_resets#new
edit_password_reset_path GET /password_resets/:id/edit(.:format) password_resets#edit
password_reset_path GET /password_resets/:id(.:format) password_resets#show
PATCH /password_resets/:id(.:format) password_resets#update
PUT /password_resets/:id(.:format) password_resets#update
DELETE /password_resets/:id(.:format) password_resets#destroy
sessions_path GET /sessions(.:format) sessions#index
POST /sessions(.:format) sessions#create
new_session_path GET /sessions/new(.:format) sessions#new
edit_session_path GET /sessions/:id/edit(.:format) sessions#edit
session_path GET /sessions/:id(.:format) sessions#show
PATCH /sessions/:id(.:format) sessions#update
PUT /sessions/:id(.:format) sessions#update
DELETE /sessions/:id(.:format) sessions#destroy
items_path GET /items(.:format) items#index
POST /items(.:format) items#create
new_item_path GET /items/new(.:format) items#new
edit_item_path GET /items/:id/edit(.:format) items#edit
item_path GET /items/:id(.:format) items#show
PATCH /items/:id(.:format) items#update
PUT /items/:id(.:format) items#update
DELETE /items/:id(.:format) items#destroy
password_Resets_path GET /password/Resets(.:format) password#Resets
password_create_path GET /password/create(.:format) password#create
password_edit_path GET /password/edit(.:format) password#edit
password_update_path GET /password/update(.:format) password#update
Try this
<%= simple_form_for :session, :url => sessions_path do |f| %>
# rest of the form
<% end %>
I've been struggling for a while with this one. I have a Rails4/Devise 3.1 app with two users in the system:
Graduates
Employers
and one devise User who can be either a Graduate or Employer via a polymorphic :profile association. I have Graduates sign up via /graduate/sign_up path and employers via /employer/sign_up path both of which route to the same /views/devise/registrations/new.html.erb view (since their signup form is pretty much the same - email and password). Everything works fine, except when there is a validation error, RegistrationsController#create.respond_with resource always redirects both user types to /users path and I need to redirect them back to where they originally came from, e.g. /graduate/sign_up or /employer/sign_up respectively. I've tried replacing respond_with with redirect_to, but I end up loosing the resource object with associated error messages. Any idea guys on how this can be done?
These are my models:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :profile, polymorphic: true
end
class Graduate < ActiveRecord::Base
has_one :user, as: :profile
end
class Employer < ActiveRecord::Base
has_one :user, as: :profile
end
Registrations controller:
class RegistrationsController < Devise::RegistrationsController
def create
build_resource sign_up_params
user_type = params[:user][:user_type]
# This gets set to either 'Graduate' or 'Employer'
child_class_name = user_type.downcase.camelize
resource.profile = child_class_name.constantize.new
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords(resource)
respond_with resource
end
end
end
Registration view (same for both, graduates and employers):
<h2>Sign up</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<%= hidden_field resource_name, :user_type, value: params[:user][:user_type] %>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render "devise/shared/links" %>
These are my routes:
devise_for :users, :controllers => { :registrations => 'registrations' }
devise_scope :user do
match 'graduate/sign_up', to: 'registrations#new', user: { user_type: 'graduate' }, via: [:get]
match 'employer/sign_up', to: 'registrations#new', user: { user_type: 'employer' }, via: [:get]
end
root to: 'home#index'
Output of rake routes;
$ rake routes
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PATCH /users(.:format) registrations#update
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#destroy
graduate_sign_up GET /graduate/sign_up(.:format) registrations#new {:user=>{:user_type=>"graduate"}}
employer_sign_up GET /employer/sign_up(.:format) registrations#new {:user=>{:user_type=>"employer"}}
root GET /
Apparently, the :location parameter is ignored if you have an existing template called, well, in this case, #index. I still don't understand why Devise redirects to #index or #show when the resource has errors on it.
I'll update this answer as I find out more.
Calling respond_with will render the default action of that resource. This I believe is the index action (/users/) and thus the cause for the redirect.
I think what you want to do is render the new action instead. Try the following:
if resource.save
...
else
clean_up_passwords(resource)
render :action => 'new'
end
In case of respond_with, for an html response - if the request method is get, an exception is raised but for other requests such as post the response depends on whether the resource has any validation errors (i.e. assuming that an attempt has been made to save the resource, e.g. by a create action) -
If there are no errors, i.e. the resource was saved successfully, the
response redirect's to the resource i.e. its show action.
If there are validation errors, the response renders a default action,
which is :new for a post request or :edit for patch or put.
source: http://apidock.com/rails/v4.1.8/ActionController/MimeResponds/respond_with
For your case, something like render 'view_path' in place of respond_with block should work.
I am stuck in weird problem. I have few recall values that are created and deleted correctly, but when i try to edit the values and save them, it created new recall.
here is my controller for Edit/update
def edit
#recall = Recall.find(params[:id])
end
def update
#recall = Recall.find(params[:id])
if #recall.update_attributes(params[:recall])
# Handle a successful update.
flash[:success] = "Recall updated"
redirect_to '/recalls'
else
render 'edit'
end
end
def show
#user = Recall.find(params[:id])
end
my edit.html.erb is as follows
<%= form_for(#recall) do |f| %>
<%= f.label :Category, "Category" %>
<div class="control-group">
<div class="controls">
<%= f.select :Category,options_for_select(["Consumer Products",
"Foods, Medicines, Cosmetics",
"Meat and Poultry Products",
"Motor Vehicles",
"Child Safety Seats",
"Tires",
"Vehicle Emissions",
"Environmental Products",
"Boats and Boating Safety"]), {:style => "height:40px"} %>
</div>
</div>
<div class="form-inline">
<%= f.label :Title, "Title" %>
</div>
<%= f.text_field :Title %>
<div class="form-inline">
<%= f.label :Summary, "Summary" %>
</div>
<%= f.text_field :Summary %>
<div class="form-inline">
<%= f.label :Details, "Details" %>
</div>
<%= f.password_field :Details %>
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
<% end %>
please let me know where i did wrong. i tried to define :action => 'edit' but it didn't worked out.
Thanks in advance
EDIT
rake routes output is here
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
root / administrator_pages#home
signup /signup(.:format) users#new
signin /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
about /about(.:format) administrator_pages#about
recalls /recalls(.:format) administrator_pages#Recalls
recall /recall(.:format) administrator_pages#create
destroy /destroy(.:format) administrator_pages#destroy
edit /edit(.:format) administrator_pages#edit
users_new GET /users/new(.:format) users#new
paid_user_paid GET /paid_user/paid(.:format) paid_user#paid
basic_user_basic GET /basic_user/basic(.:format) basic_user#basic
search_Search GET /search/Search(.:format) search#Search
here is my routes.rb, looking at rake routes and my routes.rb i can see something wrong. but unable to firgure out the problem
resources :users
resources :sessions, only: [:new, :create, :destroy]
root to: 'administrator_pages#home'
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match '/about', to: 'administrator_pages#about'
match '/recalls', to: 'administrator_pages#Recalls'
match 'recall', to:'administrator_pages#create'
match 'destroy', to: 'administrator_pages#destroy'
match 'edit', to: 'administrator_pages#edit'
# get "administrator_pages/Recalls"
get "users/new"
get "paid_user/paid"
get "basic_user/basic"
get "search/Search"
I'm not seeing an update method on your routes, just add to your routes.rb
(if an update method on administrator_pages_controller.rb)
match '/recalls', to: 'administrator_pages#recalls', :as => :recalls
match '/edit/:id', to: 'administrator_pages#edit', :as => :edit_recall
put '/update/:id', to: 'administrator_pages#update'm :as => :update_recall
And run rake routes and you will see looks like
recalls GET /recalls administrator_pages#recalls
edit_recall GET /edit/:id(.:format) administrator_pages#edit
update_recall PUT /update/:id(.:format) administrator_pages#update
http://localhost:3000/recalls recalls action
http://localhost:3000/edit/:id edit action
http://localhost:3000/update/:id update action
Your form edit looks like :
<%= form_for(#recall, :url => update_recall_path(#recall), :html => { :method => :put }) do |f| %>
:url => update_recall_path(#recall) for call update action and using :html => { :method => :put }
Your controller update method
def update
#recall = Recall.find(params[:id])
if #recall.update_attributes(params[:recall])
# Handle a successful update.
flash[:success] = "Recall updated"
redirect_to recalls_path
else
render 'edit'
end
end
recalls_path is after update will redirect into http://localhost:3000/recalls
I have try it on my localhost like your code and it's works. Hope this help.
Started PUT "/update/1" for 127.0.0.1 at 2013-07-02 20:37:14 +0700
Processing by AdministratorPagesController#update as HTML
Parameters: {"utf8"=>"V", "authenticity_token"=>"s0tVbNt0JedecA+iCVlJ9GmIhGCsf
ltTbb1ep+mZmcY=", "recall"=>{"name"=>"test"}, "commit"=>"Update Recall", "id"=>"1"
}
←[1m←[36mRecall Load (0.0ms)←[0m ←[1mSELECT "recalls".* FROM "recalls" WHERE "recalls"."id" = ? LIMIT 1←[0m [["id", "1"]]
←[1m←[35m (0.0ms)←[0m begin transaction
←[1m←[36m (1.0ms)←[0m ←[1mUPDATE "recalls" SET "name" = 'test', "updated_at" =
'2013-07-02 20:37:14.772915' WHERE "recalls"."id" = 1←[0m
←[1m←[35m (6.0ms)←[0m commit transaction
Redirected to http://localhost:3000/recalls
Completed 302 Found in 13ms (ActiveRecord: 7.0ms)
you need to send an id of a recallwithin your route, because in edit/update actions you do:
#recall = Recall.find(params[:id])
your route for edit should look like this:
match 'edit/:id', to: 'administrator_pages#edit', as: 'edit_recall'
and looks like you'll need one more for update but with method: :put
with the above route you'll have a url like this:
localhost:3000/3/edit #3 is the id of recall
but if you want administrator_pages ahead you'll have to modify your routes:
match 'administrator_pages/recall/edit/:id', to: 'administrator_pages#edit', as: 'edit_recall'
result:
localhost:3000/administrator_pages/recall/3/edit
at the request params of id will be sent and you can use that Recall.find(params[:id]) in your controller. And you'll have to draw a route for update action too with method put
A better solution, I would add resource recalls to routes:
resources :recalls
this would give me all needed routes to work with recall, edit, new, show, etc..
Try the following code
<%= form_for(#recall, :url => recall_path(#recall), :method => 'PUT') do |f| %>
This question is admittedly long. So I appreciate any support from the rubytutorial community. I am in Chapter 9, attempting to create a session for a logged-in user.
I've done the tutorial already in < Rails 3.1. Since I am now using Rails 3.1, I headed on over to Chapter 13 and linked to the (very good) Railscasts (#270) on the subject. I was able to rewrite my user sign up pretty easily thanks to has_secure_password.
When I try to log in with a user in the database I see this in the console):
No route matches {:action=>"show", :controller=>"users"}
Seems like I need to create a route and it should work. But if that is the case, why can I go 'users/1' and the view appear? I am using the route user_path(#user), #user in my sessions and users controllers (below).
Here is what I did.
Pass a form to the Session controller new action (note: I use form_tag and not form_for)
<%= form_tag sessions_path do %>
<div class="field">
<%= label_tag :email %><br />
<%= text_field_tag :email, params[:email] %>
</div>
<div class="field">
<%= label_tag :password %><br />
<%= password_field_tag :password %>
</div>
<div class="actions">
<%= submit_tag "Sign In" %>
</div>
<% end %>
Then, create action in sessions_controller.rb
def create
#Assign object by email attribute
user = User.find_by_email(params[:email])
# User is present and has access, must be true otherwise nil object
if user && user.authenticate(params[:password])
session[:user_id] = user.id
RIGHT HERE IS THE PROBLEM
redirect_to user_path(#user), :notice => "Logged in!"
else
#Use flash.now on render not flash[]
flash.now.alert = "Invalid email or password"
render "new"
end
end
And finally Create action for users_controller.rb, which works fine.
def create
#user = User.new(params[:user])
if #user.save
flash[:success] = "Welcome to the Sample App!"
redirect_to #user
else
render "new"
#user.password.clear
#user.password_confirmation.clear
end
end
Leaving my User model:
attr_accessible :name, :email, :password, :password_confirmation
email_regex = /\A[\w+\-.]+#[a-z\d\-.]+\.[a-z]+\z/i
has_secure_password
Oh and here is my current routes.rb file
resources :users
resources :sessions, only: [:create, :new, :destroy]
root to: "pages#home"
match "/about", to: "pages#about"
match "/contact", to: "pages#contact"
match "/help", to: "pages#help"
match "/signup", to: "users#new"
match "/signin", to: "sessions#new"
match "/signout", to: "sessions#destroy"
And finally my output when I run rake routes:
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
sessions POST /sessions(.:format) {:action=>"create", :controller=>"sessions"}
new_session GET /sessions/new(.:format) {:action=>"new", :controller=>"sessions"}
session DELETE /sessions/:id(.:format) {:action=>"destroy", :controller=>"sessions"}
root / {:controller=>"pages", :action=>"home"}
about /about(.:format) {:controller=>"pages", :action=>"about"}
contact /contact(.:format) {:controller=>"pages", :action=>"contact"}
help /help(.:format) {:controller=>"pages", :action=>"help"}
signup /signup(.:format) {:controller=>"users", :action=>"new"}
signin /signin(.:format) {:controller=>"sessions", :action=>"new"}
signout /signout(.:format) {:controller=>"sessions", :action=>"destroy"}
It's your redirect_to #user and/or user_path(#user) lines. They generate requests to /users/:id, which apparently isn't in your routes.rb.
#user is nil in your example - you're assigning to user. What rails is telling you in a not very helpful way is that it can't route to :controller => 'users', :action => 'show' without a user.