编辑:我看过其中的一些,但找不到答案,所以我试图尽我所能记录下来并提出这个问题。
我有一个带有嵌套评论资源的无模型 Rails 应用程序(调用 API)。如果我直接转到comments#new 或comments#index 操作并相应地发布到comments#create 操作,我可以针对故事发表评论。
但是,我非常希望能够在与父资源的#show 操作相同的页面上发表评论:(opusses#show)
我尝试使用来自 rake 路由的 rails url_helper 路径作为 opuss_comments_path 并明确说明控制器和操作。在这两种情况下,我仍然收到此消息:
No route matches {:controller=>"comments", :action=>"create"}
这是我的路线数据库:
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :osessions, only: [:new, :create, :destroy]
resources :authors do
member do
get :following
get :followed
post :follow
end
end
resources :opusses do
resources :comments
member do
get :like
get :authorfeed
post :repost
end
end
还有我的耙子路线:
DELETE /authors/:id(.:format) authors#destroy
opuss_comments GET /opusses/:opuss_id/comments(.:format) comments#index
POST /opusses/:opuss_id/comments(.:format) comments#create
new_opuss_comment GET /opusses/:opuss_id/comments/new(.:format) comments#new
edit_opuss_comment GET /opusses/:opuss_id/comments/:id/edit(.:format) comments#edit
opuss_comment GET /opusses/:opuss_id/comments/:id(.:format) comments#show
PUT /opusses/:opuss_id/comments/:id(.:format) comments#update
DELETE /opusses/:opuss_id/comments/:id(.:format) comments#destroy
&&
like_opuss GET /opusses/:id/like(.:format) opusses#like
authorfeed_opuss GET /opusses/:id/authorfeed(.:format) opusses#authorfeed
repost_opuss POST /opusses/:id/repost(.:format) opusses#repost
opusses GET /opusses(.:format) opusses#index
POST /opusses(.:format) opusses#create
new_opuss GET /opusses/new(.:format) opusses#new
edit_opuss GET /opusses/:id/edit(.:format) opusses#edit
opuss GET /opusses/:id(.:format) opusses#show
PUT /opusses/:id(.:format) opusses#update
DELETE /opusses/:id(.:format) opusses#destroy
当我从 comments#index 页面调用下面的代码时,它工作得很好。但是,从不同的控制器发布到另一个表单是很常见的,当我从 opuses#show 页面调用此代码时,它会因上述错误而失败。
如果它与 URL 帮助程序有关,我尝试明确指定控制器和操作,但仍然不起作用 - 产生了相同的错误。