Ruby on rails 3.2 继承的\u资源提供了错误的资源\u路径
我使用的是Rails 3.2.16和继承的资源1.4.1。我需要一个快速广告定制管理员,所以我以这篇文章为例(它对rails 3.2仍然有效): 这就是我的路由文件的外观:Ruby on rails 3.2 继承的\u资源提供了错误的资源\u路径,ruby-on-rails-3.2,inherited-resources,Ruby On Rails 3.2,Inherited Resources,我使用的是Rails 3.2.16和继承的资源1.4.1。我需要一个快速广告定制管理员,所以我以这篇文章为例(它对rails 3.2仍然有效): 这就是我的路由文件的外观: namespace :backend do root to: 'conferences#index' resources :conferences do resources :talks resources :sponsors end end 我的Backend::
namespace :backend do
root to: 'conferences#index'
resources :conferences do
resources :talks
resources :sponsors
end
end
我的Backend::conferencescoontroller
和Backend::sponsorscoontroller
它们都是从Backend::ResourceController
继承的,详情见博客文章
我发现的问题是,每当我进入赞助商
索引页面时,我都会得到一个命名错误
:
NoMethodError: undefined method `backend_sponsor_path' for #<Backend::SponsorsController:0x007fa588113e08>
NoMethodError:未定义的方法“后端赞助商路径”#
奇怪的是,resource\u path
方法试图查找backend\u赞助商\u path
,而不是路由中声明的backend\u conference\u赞助商\u path
有人知道如何解决这个问题吗?继承的资源不应该找到正确的路径吗
谢谢 好的,通过将
所属内容\u to:conference
添加到赞助商控制器中,问题已得到解决:
class Backend::SponsorsController < Backend::ResourceController
belongs_to :conference
end
类后端::发起人控制器
现在,路线已按预期生成!:)