2016-11-27 42 views
2

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

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

我无法更新任何图库或文章。我的整个的routes.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 
+0

您能否请自己显示错误 –

+0

http://imgur.com/a/HoJV2 – Kuba

回答

0

它看起来像请求(文章/ 12 PAGE_ID = 4?)是通过对匹配语句,而不是下降得到你的资源接走。你的对手声明:

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

是匹配“的文章”作为控制器,并寻找“12”的动作,它显然不能找到它。

我会放弃匹配语句并严格使用命名路由或资源丰富的路由,或者至少在调试时。接下来,运行

rake routes 

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

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

如果情况确实如此,请确保您有在文章控制器中定义的show()方法,并验证日志正在显示一个GET请求。