neezer
neezer

Reputation: 20560

Have Devise failed validation remain on same URL?

I'm trying to do this Use custom route upon model validation failure with Devise, and I'm not having any luck.

I've got my routes specified like this:

# authentication routing
devise_for :users do
  get "/login" => "devise/sessions#new"
  get "/logout" => "devise/sessions#destroy"
  get "/register" => "devise/registrations#new"
end

But when validation fails, say on the /register page, the URL changes back to /users.

I want the URL to stay at /register when validation fails. How would I do this?

Upvotes: 3

Views: 1533

Answers (1)

neezer
neezer

Reputation: 20560

Balls. Again I figure it out moments after posting by--wouldn't you know it?--reading.

Looking at How to change the login and signup urls in devise plugin Rails3 and https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes again, I now have this:

# authentication routing
devise_for :users, :controllers => { :sessions => 'devise/sessions' }, :skip => [:sessions] do
  get "/login" => "devise/sessions#new", :as => :new_user_session
  post "/login" => "devise/sessions#create", :as => :user_session
  get "/logout" => "devise/sessions#destroy", :as => :destroy_user_session
  get "/register" => "devise/registrations#new", :as => :new_user_registration
  post "/register" => "devise/registrations#create", :as => :user_registration
end

Which appears to work as expected.

Upvotes: 4

Related Questions