2013-03-21 42 views
0

我在我的Devise应用程序中输入新电子邮件,密码和密码确认。当我去真正做了注册,我得到以下错误:Devise:RoutingError阻止注册新用户

RoutingError

No route matches [POST] "https://stackoverflow.com/users/sign_up"

Try running rake routes for more information on available routes.

看起来new_registration_path把你带到users/sign_up,它不知道(至少得到一个POST时)。我如何让它认识到这一点?

下面是一些相关的代码位。


这里的(可能)相关routes.rb

devise_for :users 
resources :users 

下面是rake routes输出:

 new_user_session GET /users/sign_in(.:format)  devise/sessions#new 
      user_session POST /users/sign_in(.:format)  devise/sessions#create 
    destroy_user_session DELETE /users/sign_out(.:format)  devise/sessions#destroy 
      user_password POST /users/password(.:format)  devise/passwords#create 
     new_user_password GET /users/password/new(.:format) devise/passwords#new 
     edit_user_password GET /users/password/edit(.:format) devise/passwords#edit 
         PUT /users/password(.:format)  devise/passwords#update 
cancel_user_registration GET /users/cancel(.:format)  devise/registrations#cancel 
     user_registration POST /users(.:format)    devise/registrations#create 
    new_user_registration GET /users/sign_up(.:format)  devise/registrations#new 
    edit_user_registration GET /users/edit(.:format)   devise/registrations#edit 
         PUT /users(.:format)    devise/registrations#update 
         DELETE /users(.:format)    devise/registrations#destroy 
     static_pages_home GET /static_pages/home(.:format) static_pages#home 
        users GET /users(.:format)    users#index 
         POST /users(.:format)    users#create 
       new_user GET /users/new(.:format)   users#new 
       edit_user GET /users/:id/edit(.:format)  users#edit 
        user GET /users/:id(.:format)   users#show 
         PUT /users/:id(.:format)   users#update 
         DELETE /users/:id(.:format)   users#destroy 
       businesses GET /businesses(.:format)   businesses#index 
         POST /businesses(.:format)   businesses#create 
      new_business GET /businesses/new(.:format)  businesses#new 
     ed it_business GET /businesses/:id/edit(.:format) businesses#edit 
       business GET /businesses/:id(.:format)  businesses#show 
         PUT /businesses/:id(.:format)  businesses#update 
         DELETE /businesses/:id(.:format)  businesses#destroy 
        root  /       static_pages#home 

下面是注册的形式/ new.html.erb:

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

回答

3

我认为你应该使用registration_path而不是new_registration_path,因为注册是通过POST请求到/users执行的。

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

完美 - 谢谢。 – 2013-03-21 22:05:47