I am trying to implement a second devise resource of users to my Rails app. Log in works, but currently when logging out in one section, logs out both.
How can I set up my application in order to be able to keep both separated?
routes.rb:
devise_for :users, :path => 'users'
devise_for :admins, :path => 'admins'
application_controller.rb:
private
# Overwriting the sign_out redirect path method
def after_sign_out_path_for(resource_or_scope)
if resource_or_scope == :user
collection_path
elsif resource_or_scope == :admin
new_admin_session_path
else
root_path
end
end
# Overwriting the sign_in redirect path method
def after_sign_in_path_for(resource)
stored_location_for(resource) ||
if resource.is_a?(User)
collection_opac_path
elsif resource.is_a?(Admin)
admin_root_path
else
super
end
end
1.html
<%= link_to 'Log out', destroy_admin_session_path, :method => :delete %>
2.html
<%= link_to 'Log out', destroy_user_session_path, :method => :delete %>
LOG upon logging out user:
Started DELETE "/users/sign_out" for 127.0.0.1 at Fri Feb 08 18:28:11 +0100 2019
Processing by Devise::SessionsController#destroy as HTML
Parameters: {"authenticity_token"=>"somestring"}
User Load (0.7ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Admin Load (0.4ms) SELECT `admins`.* FROM `admins` WHERE `admins`.`id` = 1 LIMIT 1
SQL (0.1ms) BEGIN
(0.4ms) UPDATE `users` SET `updated_at` = '2019-02-08 17:28:11', `remember_created_at` = NULL WHERE `users`.`id` = 1
(0.8ms) COMMIT
SQL (0.1ms) BEGIN
(0.2ms) UPDATE `admins` SET `remember_created_at` = NULL, `updated_at` = '2019-02-08 17:28:11' WHERE `admins`.`id` = 1
(0.3ms) COMMIT
Redirected to http://localhost:3000/collection
Completed 302 Found in 10ms (ActiveRecord: 2.9ms)
Aucun commentaire:
Enregistrer un commentaire