Specifying redirect paths for multiple devise models

337 views
Skip to first unread message

ericindc

unread,
Nov 1, 2010, 7:03:04 PM11/1/10
to Devise
I have a user model and a partner model, both of which are handled via
Devise. I would like to modify the sign in, sign out, and failed
authentication redirects for partner, but am not seeing how to do
this.

Currently /partners/sign_in redirects to /login on a failed
authentication because /login is where I have my user sign in going.
Is there an easy way to specify specific paths for just the partner
pieces?

ericindc

unread,
Nov 1, 2010, 7:03:10 PM11/1/10
to Devise

Code Daemon

unread,
Nov 1, 2010, 8:16:49 PM11/1/10
to Devise
Can you paste your routes?

ericindc

unread,
Nov 1, 2010, 9:26:50 PM11/1/10
to Devise
devise_for :user, :skip => [:sessions, :registration, :passwords] do
scope :controller => 'devise/sessions' do
get :new, :path => 'login', :as => :new_user_session
post :create, :path => 'login', :as => :user_session
get :destroy, :path => 'logout', :as => :destroy_user_session
end

scope :controller => 'devise/passwords' do
get :new, :path => "password/reset", :as
=> :new_user_password
post :create, :path => "password/update", :as => :user_password
put :update, :path => "password/update", :as => :user_password
get :edit, :path => "password/update", :as
=> :edit_user_password
end

scope :controller => 'registration' do
get :new, :path => 'register', :as
=> :new_user_registration
post :create, :path => 'register', :as
=> :user_registration
get :edit, :path => 'register/edit', :as
=> :edit_user_registration
put :update, :path => 'register', :as
=> :user_registration
end
end

devise_for :partners

Code Daemon

unread,
Nov 1, 2010, 9:48:24 PM11/1/10
to Devise
Try moving both devise_for to the top. Also, not sure you need those
fancy scopes, you can just do something like:

devise_for :partners, :path_names = { :sign_in =>
'login', .... }, :path => "/partners"

ericindc

unread,
Nov 2, 2010, 9:56:08 AM11/2/10
to Devise
The customized routes are for the user paths only. I don't want/need
to change anything about partners.

I think my problem is in the views. I have custom views for users
that were previous stored as app/views/devise/.. so /partners/sign_in
was rendering those views as well. I've moved the views to app/views/
users/.. and changed my config file to look for scoped views and have
a default scope of users, but now the default Devise views are being
rendered instead of my custom ones.

What am I missing?

ericindc

unread,
Nov 2, 2010, 10:20:33 AM11/2/10
to Devise
Ok, I'm getting closer...

I had to move my views to app/views/user and it seems to load fine.
The problem now, is that the semantic_form_for(resource, :as =>
resource_name, :url => session_path(resource_name)) tag is generating
session_path(partner) as /login and I'm not sure why. I've tossed in
a couple of print statements and the resource is a partner object.
Reply all
Reply to author
Forward
0 new messages