我是Ruby on Rails的新手,我正在开发一个包含用于创建新提名者的表单的应用程序(将其存储在数据库中) 我通过以下形式的说明得到了问题:
<%= form_for :subscription, :url => {:controller => "subscriptions", :action => "create"} do |f| %>
这是错误:
Routing Error
No route matches [POST] "/subscriptions/create"
rake routes
Prefix Verb URI Pattern Controller#Action
subscriptions_create GET /subscriptions/create(.:format) subscriptions#create
subscriptions_index GET /subscriptions/index(.:format) subscriptions#index
articles_index GET /articles/index(.:format) articles#index
new_admin_user_session GET /admin/login(.:format) active_admin/devise/sessions#new
admin_user_session POST /admin/login(.:format) active_admin/devise/sessions#create
destroy_admin_user_session DELETE|GET /admin/logout(.:format) active_admin/devise/sessions#destroy
admin_user_password POST /admin/password(.:format) active_admin/devise/passwords#create
new_admin_user_password GET /admin/password/new(.:format) active_admin/devise/passwords#new
edit_admin_user_password GET /admin/password/edit(.:format) active_admin/devise/passwords#edit
PATCH /admin/password(.:format) active_admin/devise/passwords#update
PUT /admin/password(.:format) active_admin/devise/passwords#update
admin_root GET /admin(.:format) admin/dashboard#index
batch_action_admin_admin_users POST /admin/admin_users/batch_action(.:format) admin/admin_users#batch_action
admin_admin_users GET /admin/admin_users(.:format) admin/admin_users#index
POST /admin/admin_users(.:format) admin/admin_users#create
new_admin_admin_user GET /admin/admin_users/new(.:format) admin/admin_users#new
edit_admin_admin_user GET /admin/admin_users/:id/edit(.:format) admin/admin_users#edit
admin_admin_user GET /admin/admin_users/:id(.:format) admin/admin_users#show
PATCH /admin/admin_users/:id(.:format) admin/admin_users#update
PUT /admin/admin_users/:id(.:format) admin/admin_users#update
DELETE /admin/admin_users/:id(.:format) admin/admin_users#destroy
batch_action_admin_contacts POST /admin/contacts/batch_action(.:format) admin/contacts#batch_action
admin_contacts GET /admin/contacts(.:format) admin/contacts#index
POST /admin/contacts(.:format) admin/contacts#create
new_admin_contact GET /admin/contacts/new(.:format) admin/contacts#new
edit_admin_contact GET /admin/contacts/:id/edit(.:format) admin/contacts#edit
admin_contact GET /admin/contacts/:id(.:format) admin/contacts#show
PATCH /admin/contacts/:id(.:format) admin/contacts#update
PUT /admin/contacts/:id(.:format) admin/contacts#update
DELETE /admin/contacts/:id(.:format) admin/contacts#destroy
admin_dashboard GET /admin/dashboard(.:format) admin/dashboard#index
admin_comments GET /admin/comments(.:format) admin/comments#index
POST /admin/comments(.:format) admin/comments#create
admin_comment GET /admin/comments/:id(.:format) admin/comments#show
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
welcome_sponsor GET /welcome/sponsor(.:format) welcome#sponsor
welcome_photo GET /welcome/photo(.:format) welcome#photo
welcome_index GET /welcome/index(.:format) welcome#index
root GET / welcome#index
最好的考虑
答案 0 :(得分:2)
从下面的行中可以看出:
Prefix Verb URI Pattern Controller#Action
subscriptions_create GET /subscriptions/create(.:format) subscriptions#create
你有一个subscriptions_create的路由,但它需要是POST而不是GET。只需在config文件夹中的routes.rb文件中将此路由更新为POST而不是GET。
答案 1 :(得分:1)
从这一行可以看出
subscriptions_create GET /subscriptions/create(.:format)
,该路由仅在使用GET
HTTP方法时可用。
您需要更改您的routes.rb文件以便订阅接受POST而不是GET。最简单的方法是添加resources :subscriptions
,它将为资源添加所有标准CRUD路由。