Reputation: 797
i have three devise :
devise_for :hrs
devise_for :employes
devise_for :authorizes
If i signed in as :authorize
in application_controller.rb
def after_sign_in_path_for(authorize)
auth_main_path
end
def after_sign_out_path_for(authorize)
new_authorize_session_path
end
def after_sign_in_path_for(employe)
employee_emain_path
end
def after_sign_out_path_for(employe)
new_employe_session_path
end
def after_sign_in_path_for(hr)
hrs_hhome_path
end
def after_sign_out_path_for(hr)
new_hr_session_path
end
and in application.html.erb
code for sign_out
button is:
<%= link_to "SIGNOUT", destroy_authorize_session_path, :method => :delete ,:data => { confirm: 'Are you sure?' } %>
Till here it works perfectly, but as soon as i add the controller for other two devise it gives error
What should i change to the button so that it destroy the session for the current_session
If i signed in
as :hr
, then clicking on signout
it should render to specified path. Same should apply for the other devise models.
ERROR
If i press on sign_out
button i get error when i log_in as employee or hr. i want that `if i have login as employee then it should destroy the employee_session for that what changes should i do.
thank you.
Upvotes: 0
Views: 83
Reputation: 48
You can always create a method to return the correct path for the logged in user.
For example, in your ApplicationController you can add a method to get the correct sign-out path for the current user, something like
def sign_out_path
if hr_signed_in?
destroy_hr_session_url
elsif employe_signed_in?
destroy_employe_session_url
else
destroy_authorize_session_url
end
end
Then in your html, use this method instead of the path.
<%= link_to "SIGNOUT", sign_out_path, :method => :delete ,:data => { confirm: 'Are you sure?' } %>
You should really add a method to check if any user is signed-in, and only display the sign-out link then.
Upvotes: 1