Full disclosure, I'm a no00b. That said... I'm trying to use a bootstrap button that when clicked links to a devise registration page. I either get an error that I have an undefined method or it completely messes up my bootstrap format. Can someone please explain what is going on?
This line of code messes up the bootstrap formatting
<%= link_to "Sign Up", new_user_registration_path, :class => "btn btn-success" %>
Edit: rake routes path shows I have new_user_registration_path
new_user_session GET /auth/login(.:format) devise/sessions#new
user_session POST /auth/login(.:format) devise/sessions#create
destroy_user_session DELETE /auth/logout(.:format) devise/sessions#destroy
user_password POST /auth/secret(.:format) devise/passwords#create
new_user_password GET /auth/secret/new(.:format) devise/passwords#new
edit_user_password GET /auth/secret/edit(.:format) devise/passwords#edit
PATCH /auth/secret(.:format) devise/passwords#update
PUT /auth/secret(.:format) devise/passwords#update
cancel_user_registration GET /auth/register/cancel(.:format) devise/registrations#cancel
user_registration POST /auth/register(.:format) devise/registrations#create
new_user_registration GET /auth/register/cmon_let_me_in(.:format) devise/registrations#new
edit_user_registration GET /auth/register/edit(.:format) devise/registrations#edit
PATCH /auth/register(.:format) devise/registrations#update
PUT /auth/register(.:format) devise/registrations#update
DELETE /auth/register(.:format) devise/registrations#destroy
Related
I first used Devise to create authorization for Users. Then I wanted to create a separate Admin user using Devise. I followed these directions from Devise using Option 1: https://github.com/plataformatec/devise/wiki/How-To:-Add-an-Admin-role.
I created my admin model and migration, added an admin into the database Admin.create(etc...)
I added an admin button on the homepage: <%= link_to "Admin", new_admin_session_path %>
My problem is that I click the admin button, the route does takes me to: http://localhost:3000/admins/sign_in, which is correct, but when I sign in, it goes to http://localhost:3000/users/sign_in. I do have flash messages so the flash message says the admin is signed in successfully. I think it has to do with my routes, because the Devise User and Devise Admin routes are the same. How do I configure this to go to admin views(I'm going to create an admin dashboard) and not mess up Devise Admin authorizations?
Here are my current routes:
Prefix Verb URI Pattern Controller#Action
new_admin_session GET /admins/sign_in(.:format) devise/sessions#new
admin_session POST /admins/sign_in(.:format) devise/sessions#create
destroy_admin_session DELETE /admins/sign_out(.:format) devise/sessions#destroy
admin_password POST /admins/password(.:format) devise/passwords#create
new_admin_password GET /admins/password/new(.:format) devise/passwords#new
edit_admin_password GET /admins/password/edit(.:format) devise/passwords#edit
PATCH /admins/password(.:format) devise/passwords#update
PUT /admins/password(.:format) devise/passwords#update
cancel_admin_registration GET /admins/cancel(.:format) devise/registrations#cancel
admin_registration POST /admins(.:format) devise/registrations#create
new_admin_registration GET /admins/sign_up(.:format) devise/registrations#new
edit_admin_registration GET /admins/edit(.:format) devise/registrations#edit
PATCH /admins(.:format) devise/registrations#update
PUT /admins(.:format) devise/registrations#update
DELETE /admins(.:format) devise/registrations#destroy
deals_index GET /deals/index(.:format) deals#index
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) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
I have these 2 routes that are conflicting in my application
destroy_users DELETE /users/:id(.:format) users#destroy
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
the corresponding part of my routes file is as follows
match '/users/:id', to: 'users#destroy', :via => :delete, :as =>:destroy_users
devise_for :users
resources :users
When I try to destroy a session using the following link
<li><%= link_to "Sign out", destroy_user_session_path, method: "delete" %></li>
it tries to navigate to the following route
localhost:3000/users/sign_out
this is going to my UserController and trying to run the destroy method passing sign_out as a parameter rather than a route
Couldn't find User with id=sign_out
The first line in my routes file was to allow a single user to be deleted in the UserController, this is the destroy method. This had to be put before the devise_for otherwise it was trying to route to the edit_user_registration_path of devise using DELETE. Now it seems to be overwriting the devise destroy_user_session_path
I'm not sure how to fix this any advice would be appreciated
Typically, I would think devise_for :users creates the following 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) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
using your routes you get
Prefix Verb URI Pattern Controller#Action
destroy_users DELETE /users/:id(.:format) users#destroy <--- oops this should be below all the other routes
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) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#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 <--- notice it typically would be
Deleting the first match route should help you... or you can move it below your resources :users. You should skip creating destroy with resources.
Why click on link = link_to 'Logout', destroy_user_session_path, method: :delete make GET request to /users/sign_out and render show view of UsersController? My routes.rb is:
devise_for :users
resources :users, only: [:show] do
member do
get 'profile'
get 'purchases'
get 'mailing'
end
end
and /config/initializers/devise.rb contain config.sign_out_via = :delete, rake routes output is:
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) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
profile_user GET /users/:id/profile(.:format) users#profile
purchases_user GET /users/:id/purchases(.:format) users#purchases
mailing_user GET /users/:id/mailing(.:format) users#mailing
user GET /users/:id(.:format) users#show
The html generated for your logout link is as follows:
<a rel="nofollow" href="/users/sign_out" data-method="delete"></a>
This will only work if the js files are properly loaded ( I think it needs jquery_ujs )
Otherwise it defaults to a GET request.
It should be work for you.
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
Im having problems with signing out with devise, i get the following error message when i try to sign out, its looking for a user with the id=sign_out. Any suggestions?
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User with id=sign_out
Routes
devise_for :users
match 'users/settings', to: 'users#settings'
resources :users, only: [:show, :update]
Link
<%= link_to 'Logout', destroy_user_session_path, :method => :delete %>
Rake Routes
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
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
users_settings /users/settings(.:format) users#settings
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format)
Recently I've solved this problem, You need try to put or check the below line in your views/layouts/application.html.erb
<%= javascript_include_tag "application" %>
Also check if you have jquery_ujs in your Gemfile.
Make sure you're actually clicking on the correct link. I highly doubt that link routes the request to UsersController#show. destroy_user_session_path routes to /users/sign_out so this is impossible.
This error has been driving me and a fellow dev insane. We're building an app with Ruby/Rails jazz, and whenever I click to logout for a user session, I get this error:
Routing Error
No route matches [GET] "/users/sign_out"
Try running rake routes for more information on available routes.
Now I've ran rake routes a ton, and I get:
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
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root / home#index
about /about(.:format) home#about
Is there anything to be done here? I've also followed the answers of a lot of the posts here on Stack Overflow to no avail. Anything else I can test to try to fix this problem?
EDIT: Here is logout link code
<a href="/users/sign_out" class="header-links right-link" data-method="delete" rel="nofollow">Logout</a
Inspect you HTML and make sure rails.js is loaded, and there are no javascript errors. And if you are using jQuery, make sure that there is noConflict.
Note: My guess is you are running rails version < 3.1, So check if these two lines are present in your layout
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
Try:
<%= link_to "Logout", destroy_user_session_path, method: :delete %>
does your routes have this under "devise_for"? :
get 'users/sign_out' => 'sessions#destroy', :as => :destroy_user_session
And try this as link:
<%= link_to "Logout", destroy_user_session_path, method => :delete %>
Check to see if your routes.rb has,
devise_for :users, ActiveAdmin::Devise.config
Sometimes my installs seem to miss this part ActiveAdmin::Devise.configand then I get this error.
I see it in the gem's generator but sometimes it doesn't get added on my apps.