4

On the sign up and forgot password views in Devise, if you get an error, it redirects you to the parent page.

So on the sign up page (/users/sign_up), if you get an error, it redirects you to /users and shows the error.

On the forgot password page (/users/password/new), if you get an error, it redirects you to /users/password and shows the error.

How can I change it so it does the same thing as the sign in page, if there's an error, it stays on the same page and shows the error.

I've looked through Devise and can't find where the redirect is.

Here's my routes for Devise:

devise_for :users, :skip => [:sessions]
as :user do
  get 'signin' => 'devise/sessions#new', :as => :new_user_session
  post 'signin' => 'devise/sessions#create', :as => :user_session
  get 'signup' => 'devise/registrations#new', :as => :new_user
  post 'signup' => 'devise/registrations#create', :as => :create_user_session
  delete 'signout' => 'devise/sessions#destroy', :as => :destroy_user_session
  get "/account" => "devise/registrations#edit"
end
user2203362
  • 259
  • 1
  • 7
  • 11

2 Answers2

3

I think the problem is that you have the post 'signup' named incorrectly. What path does your user signup form POST to?

post 'signup' => 'devise/registrations#create', :as => :create_user_session

Should be:

post 'signup' => 'devise/registrations#create', :as => :user_registration

Here's a look at my routes.rb which solved this issue:

as :user do
  get "/signin" => "devise/sessions#new", :as => :new_user_session
  post "/signin" => "devise/sessions#create", :as => :user_session
  delete "/signout" => "devise/sessions#destroy", :as => :destroy_user_session
  get "/signup" => "devise/registrations#new", :as => :new_user_registration
  post '/signup' => 'devise/registrations#create', :as => :user_registration
end
Rob Sobers
  • 20,737
  • 24
  • 82
  • 111
-2

It doesn't redirect you anywhere, those are the URLs that Devise posts to.

If you want to edit these URLs, see the wiki for a good starting point: https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes

sevenseacat
  • 24,699
  • 6
  • 63
  • 88
  • If you go to the sign up page (/users/sign_up) and click sign up without adding any information, you get redirected to /users. – user2203362 Apr 07 '13 at 14:19
  • I just want it to be /signup and if there are any errors, to show up on that page. – user2203362 Apr 07 '13 at 14:19
  • No. `/users` is the path the form posts to. See https://github.com/plataformatec/devise/blob/master/app/views/devise/registrations/new.html.erb. – sevenseacat Apr 07 '13 at 14:20
  • Oh, I see. How can I change that to same URL? – user2203362 Apr 07 '13 at 14:22
  • see the update to my question. I've already changed them but it still does the same thing – user2203362 Apr 07 '13 at 14:28
  • It doesn't do it for the `sign_in` page though. – user2203362 Apr 07 '13 at 14:28
  • Your `post 'signup'` route name is completely incorrect, and it works for signin because you've skipped the sessions controller when defining your Devise routes. If you want it to work for signup and anything else, you need to exclude those too. – sevenseacat Apr 07 '13 at 14:30
  • I've read the wiki but I can't see anything to do with signing up. I'm sorry, I'm knew to Rails. – user2203362 Apr 07 '13 at 14:37
  • You excluded the Sessions controller from the Devise routes, and it now does what you want. How do you think you can make the Registrations controller do the same thing? – sevenseacat Apr 07 '13 at 14:39
  • I'm confused. The routes above are in my routes file, I included the new and create action for Sessions and the same for the registrations so why isn't it working? What part did I miss? – user2203362 Apr 07 '13 at 14:50
  • You *excluded the Sessions controller from the Devise routes, and it now does what you want*. – sevenseacat Apr 07 '13 at 14:51
  • OH! I see. So would `devise_for :users, :skip => [:sessions], :skip => [:registrations]` be correct? – user2203362 Apr 07 '13 at 14:54
  • It's still doing it though? Also, it didn't do it on the sign_in page even before I included `:skip => [:sessions]` – user2203362 Apr 07 '13 at 15:02