Rails 3 Devise - Getting " No route matches "/users/sign_out" " - ruby-on-rails

No route matches "/users/sign_out" When I am logged in. I just followed ryan bates tutorial to get devise working. My rake routes looks like this.
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
root /(.:format) {:controller=>"welcome", :action=>"index"}
Thanks in advance.

Routes look correct. Your sign out link should look like this:
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>

I assume the other answer solved your problem. If you want to know why, check out the section in this setup guide for rails 3.1 with devise. Basically, when you try to HTTP GET the sign out route, it doesn't exist because it's only setup for HTTP DELETE. You can see this in the second column of the routes you pasted in the question. Probably your links were missing the
:method => :delete
Also in that tutorial, you can see how to setup devise to use the GET method when it is in test mode. Change /config/initializers/devise.rb as follows:
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = Rails.env.test? ? :get : :delete

Related

Routing error with devise {:controller=>"devise/static", :action=>"about"}

I got a problem with devise. Every time I try to call an Url that should be handled by devise (e.g. http://localhost:3000/users/sign_up) I end up with the following error:
No route matches {:controller=>"devise/static", :action=>"about"}
Hopefully somebody can help me!
routes.rb
devise_for :users
get "pages/contact"
get "pages/imprint"
get "pages/about"
root :to => "pages#about"
What I did:
Added gem 'devise' to the gemfile
bundle install
rails generate devise:install
rails generate devise User
rake db:migrate
rake routes
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
pages_contact GET /pages/contact(.:format) {:controller=>"pages", :action=>"contact"}
pages_imprint GET /pages/imprint(.:format) {:controller=>"pages", :action=>"imprint"}
pages_about GET /pages/about(.:format) {:controller=>"pages", :action=>"about"}
root / {:controller=>"pages", :action=>"about"}
Rails Version:
Rails 3.1.3
PagesController
class PagesController < ApplicationController
def contact
end
def imprint
end
def about
end
end
The error for me was fixed when I changed my link_to methods.
In my header I had:
<%= link_to "Info", :controller => :info %>
and when I switched it to:
<%= link_to "Info", "/info" %>
the error was gone!

Ruby on Rails devise http://0.0.0.0:3000/users/sign_out gets routing error

routes.rb =>
Sendemail::Application.routes.draw do
devise_for :users
get "user/index"
get "home/index"
root :to => 'home#index'
end
rake routes =>
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
user_confirmation POST /users/confirmation(.:format) {:action=>"create", :controller=>"devise/confirmations"}
new_user_confirmation GET /users/confirmation/new(.:format) {:action=>"new", :controller=>"devise/confirmations"}
GET /users/confirmation(.:format) {:action=>"show", :controller=>"devise/confirmations"}
user_index GET /user/index(.:format) {:controller=>"user", :action=>"index"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}
When i type rails server i get this message every time =>
/home/user1/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV
For "http://0.0.0.0:3000/users/sign_out"
Routing Error
No route matches [GET] "/users/sign_out"
What should i do to fix this problem ?
Notice how your routes say /users/sign_out is a DELETE request. Most browsers do not make DELETE requests by default. Just going to that URL would be a GET request to /users/sign_out.
This how to add sign out links should help you get it working.
Add :method => :delete to your signout link.

Ruby on Rails: devise doesn't send email to the mailing address during sign_up

During sign_up i entered username, email, password.
After clicking the sign_up button, i checked the mail.
But i didn't get any email from devise.
How can i set/configure devise for registration confirmation email ?
Someone please help to fix this problem.
I have searched in stackoverflow and tried all but failed to solve this problem.
http://0.0.0.0:3000/users/sign_out, i get "Routing error"
http://0.0.0.0:3000/users/sign_in, i get "You are already logged in"
rake routes:
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}
users_controller.rb=>
class UsersController < ApplicationController
before_filter :authenticate_user!
def show
#user = User.find(params[:id])
end
end
I did:
rails g devise:views
for the email part, check your configuration settings for the mailer. can you even send email using actionmailer?
for the second part, with the signout process, the link you're using is calling a GET method. As you can see in your routes, to sign out you need a DELETE method in your link which will look like this:
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
If you want to use GET for sign out specifically, check out the devise initializer file; somewhere at the bottom you'll see something about signing out and the default method being :delete. put this line there:
config.sign_out_via = :get

Why does devise put /devise/ in front of every link_to anchor?

I just generated all the views for devise, and I'm starting to customize the login screen. It works great except for all the links that are generated on the sign in page start with "/devise".
Why is it doing that? Seems like odd default behaviour
How do I stop it from adding /devise to every link_to()?
My routes file:
devise_for :users
get "/webpages/:page" => "webpages#show", :as => :show_webpage
root :to => "webpages#index"
My 'rake routes'
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
show_webpage GET /webpages/:page(.:format) {:controller=>"webpages", :action=>"show"}
root /(.:format) {:controller=>"webpages", :action=>"index"}
The error message I get when I try and render a page that comes from the devise controller:
ActionController::RoutingError in Devise/sessions#new
Showing /home/egervari/Projects/training/app/views/layouts/application.html.erb where line #21 raised:
No route matches {:controller=>"devise/webpages", :action=>"show", :page=>"tour"}
Extracted source (around line #21):
18: </a>
19: </li>
20: <li>
21: <%= link_to("Tour", :controller => "webpages", :action => "show", :page => "tour") %>
22: </li>
23: <li>
24: <%= link_to("Why Use Us?", :controller => "webpages", :action => "show", :page => "why") %>
As you can see above, it's trying to add "devise/" to my link. This is not what I want at all.
I figured it out finally.
<li><%= link_to("Terms and Use", :controller => "/webpages", :action => "show", :page => "terms") %> |</li>
<li><%= link_to("Privacy Policy", :controller => "/webpages", :action => "show", :page => "privacy") %> |</li>
Basically what I did was put "/webpages" instead of "webpages" to tell rails that these controllers were not under the "devise" namespace or parent directory.
Is this the appropriate fix? Is there a simpler solution?
In newer versions of Rails you can do:
<%= link_to "Privacy Policy", show_webpage_path(:page => 'privacy') %>
You just append a _path onto the named route that you see when you do a 'rake routes'. Appending _url to the named route will give you the URL string, BTW. Which can be useful.
ian.
All links/forms targeted to devise are expected to start with "/devise". See the routes generated by devise below. Why do you want change this behavior? Is it not working? Or do you need/want to customize the devise controllers?
new_user_session GET /users/login(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/login(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/register(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
user_confirmation POST /users/confirmation(.:format) {:action=>"create", :controller=>"devise/confirmations"}
new_user_confirmation GET /users/confirmation/new(.:format) {:action=>"new", :controller=>"devise/confirmations"}
GET /users/confirmation(.:format) {:action=>"show", :controller=>"devise/confirmations"}

Ruby On Rails Application.html.haml

I am using Ruby On Rails 2.3.5 with haml version 2.2.21 (in my environment.rb file) And all the links I generate in views (using haml) adds the link itself at the end.
Ex :
%li
=link_to 'sign up', {:controller=> 'users' , :action=> 'signup'}
Displays
sign up(users/signup)
Anyone knows why ?
you should just be able to do:
=link_to 'Sign Up', user_registration_path
For future reference, you can run the command
rake routes
To get a list of all the named routes in your application:
$ rake routes
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
user_password PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
user_registration PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
user_registration DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
The route name is listed in the leftmost column. You can then append '_path' to any of those to access that path.

Resources