我在Devise应用中输入新的电子邮件,密码和密码确认。当我去实际进行注册时,我收到以下错误:
RoutingError
No route matches [POST] "/users/sign_up"
尝试运行
rake 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
以下是registrations / new.html.erb中的表单:
<%= form_for(resource, :as => resource_name, :url => new_registration_path(resource_name)) do |f| %>
...
<% end %>
答案 0 :(得分:3)
我认为您应该使用registration_path
代替new_registration_path
,因为注册是通过POST
请求/users
进行的。
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
...
<% end %>