gpt4 book ai didi

ruby-on-rails - 找不到 xyzController 的操作 x

转载 作者:太空宇宙 更新时间:2023-11-03 16:43:01 24 4
gpt4 key购买 nike

我是 Ruby on Rails 的初学者,我遇到了一个问题。我正在尝试向我的应用添加评论。一切正常,但是当我将此代码添加到 routes.rb

resources :galleries do
resources :comments, module: :galleries
end
resources :articles do
resources :comments, module: :articles
end

我无法更新任何图库或文章。我的整个路线.rb:

Rails.application.routes.draw do

devise_for :users


resources :galleries do
resources :comments, module: :galleries
end
resources :articles do
resources :comments, module: :articles
end

match ':controller(/:action(/:id))(.:format)', via: [:post, :get]


root 'public#index'
end

最佳答案

看起来请求 (articles/12?page_id=4) 正在落入匹配语句并且没有被您的资源接收。你的比赛声明:

 match ':controller(/:action(/:id))(.:format)', via: [:post, :get]

正在匹配“文章”作为 Controller ,并寻找“12”作为 Action ,但显然找不到。

我会废弃 match 语句并永久地严格使用命名路由或足智多谋的路由,或者至少在调试时。接下来,运行

rake routes

然后检查结果。从你的 routes.rb 我猜你会有这样一行:

             article GET    /articles/:id(.:format)    articles#show

如果确实如此,请确保您在文章 Controller 中定义了 show() 方法,并验证日志是否显示了针对它的 GET 请求。

关于ruby-on-rails - 找不到 xyzController 的操作 x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40829273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com