1

I'm getting an error:

NoMethodError in Devise/registrations#new

undefined method 'user_registration_path'

at this line:

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>

This is my routes:

  devise_for :user, :controllers => { :registrations => "devise/registrations" }, :skip => [:registrations, :sessions] do 
    # devise/registrations

    get 'signup' => 'devise/registrations#new', :as => :new_user_registration 
    post 'signup' => 'devise/registrations#create', :as => :custom_user_registration 
  end

Rake Routes:

      new_user_registration GET    /signup(.:format)      devise/registrations#new
   custom_user_registration POST   /signup(.:format)      devise/registrations#create

why am I getting the user_registration_path error?

RAM
  • 2,413
  • 1
  • 21
  • 33
hellomello
  • 8,219
  • 39
  • 151
  • 297

2 Answers2

4

Running rake routes, do you see in output smth like this:

user_registration POST    /users(.:format)     devise/registrations#create

I think if you wrote this line

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

Now you have:

custom_user_registration POST    /signup(.:format)     devise/registrations#create

And should use custom_user_registration_path(resource_name) instead of registration_path(resource_name)

zolter
  • 7,070
  • 3
  • 37
  • 51
  • It also raise error undefined method 'custom_user_registration_path'? – zolter Aug 22 '13 at 03:29
  • actually, its a different error. I think because I have this: `<%= devise_error_messages! %>` and i'm getting undefined method 'errors'. If I delete that, then it works! But how do you do it so that error message works too? – hellomello Aug 22 '13 at 03:31
  • Your error message like this? http://stackoverflow.com/questions/11219670/devise-error-messages-causes-undefined-method-errors-for-nilnilclass – zolter Aug 22 '13 at 03:37
1

You are skipping the registrations routes and not overriding them all with the custom routes you've defined. Remove :registrations from the skipped routes. In your routes.rb:

This

devise_for :user, :controllers => { :registrations => "devise/registrations" }, :skip => [:registrations, :sessions] do

should be

devise_for :user, :controllers => { :registrations => "devise/registrations" }, :skip => [:sessions] do

Or you can add these custom routes if you want the path to always be /signup:

devise_for :user, :controllers => { :registrations => "devise/registrations" }, :skip => [:registrations, :sessions] do 
  get 'signup' => 'devise/registrations#new', :as => :new_user_registration 
  post 'signup' => 'devise/registrations#create', as => :user_registration
  delete 'signup' => 'devise/registrations#destroy', as => :destroy_user_registration
end

I don't advise changing the helper names (as => :whatever) since the devise controllers and views use them. It's fine to add new ones. I'm not sure you need to specify the controller either if it's the default.

tee
  • 4,149
  • 1
  • 32
  • 44