【发布时间】:2018-06-08 15:17:18
【问题描述】:
我无法访问在我运行路由时似乎没有嵌套但嵌套在 routes.rb 中的路由
Prefix Verb URI Pattern Controller#Action
sort_list POST /lists/:id/sort(.:format) lists#sort
list POST /lists/:id(.:format) lists#create
list_items GET /lists/:list_id/items(.:format) items#index
POST /lists/:list_id/items(.:format) items#create
new_list_item GET /lists/:list_id/items/new(.:format) items#new
edit_item GET /items/:id/edit(.:format) items#edit
item GET /items/:id(.:format) items#show
PATCH /items/:id(.:format) items#update
PUT /items/:id(.:format) items#update
DELETE /items/:id(.:format) items#destroy
project_lists GET /projects/:project_id/lists(.:format) lists#index
POST /projects/:project_id/lists(.:format) lists#create
new_project_list GET /projects/:project_id/lists/new(.:format) lists#new
edit_list GET /lists/:id/edit(.:format) lists#edit
GET /lists/:id(.:format) lists#show
PATCH /lists/:id(.:format) lists#update
PUT /lists/:id(.:format) lists#update
DELETE /lists/:id(.:format) lists#destroy
projects GET /projects(.:format) projects#index
POST /projects(.:format) projects#create
new_project GET /projects/new(.:format) projects#new
edit_project GET /projects/:id/edit(.:format) projects#edit
project GET /projects/:id(.:format) projects#show
PATCH /projects/:id(.:format) projects#update
PUT /projects/:id(.:format) projects#update
DELETE /projects/:id(.:format) projects#destroy
react POST /react(.:format) reacts#create
new_react GET /react/new(.:format) reacts#new
edit_react GET /react/edit(.:format) reacts#edit
GET /react(.:format) reacts#show
PATCH /react(.:format) reacts#update
PUT /react(.:format) reacts#update
DELETE /react(.:format) reacts#destroy
这里是 Routes.rb
Rails.application.routes.draw do
resources :projects do
resources :lists, shallow: true do
member do
post :sort
end
resources :items, shallow: true
end
end
resource :react
end
还有我的link_to
<%= link_to %(<span class="glyphicon glyphicon-trash"></span>).html_safe, controller: :lists, action: :create ,remote: true, method: :post %>
我得到了错误
No route matches {:action=>"create", :controller=>"lists", :method=>:post}
我很困惑,因为当我 rake 路由时,它返回列表有一个创建操作。我显然无法正常访问它。感谢您的帮助。
【问题讨论】:
-
重新启动服务器后尝试 rake 路由是否显示相同的路由?我认为他们不应该是 2
lists#create。 -
是的,没错。我重新启动了服务器,现在只有一个 list#create POST /projects/:project_id/lists(.:format) lists#create
标签: ruby-on-rails routes link-to