Ruby on rails 继承的_资源-转到父级
我有2个继承的资源(带有Jose Valim插件)-博客和帖子。当然-博文hm博文和博文bt博文。路线就足够了Ruby on rails 继承的_资源-转到父级,ruby-on-rails,ruby,ruby-on-rails-3,inherited-resources,Ruby On Rails,Ruby,Ruby On Rails 3,Inherited Resources,我有2个继承的资源(带有Jose Valim插件)-博客和帖子。当然-博文hm博文和博文bt博文。路线就足够了 resources :blogs, :only => [:show] do resources :posts end 此外,我还用以下内容更新了行动帖子索引 def index redirect_to parent_url end 正如我所计划的-在尝试访问时,我将被重定向到,但我看到路由错误 No route matches {:action
resources :blogs, :only => [:show] do
resources :posts
end
此外,我还用以下内容更新了行动帖子索引
def index
redirect_to parent_url
end
正如我所计划的-在尝试访问时,我将被重定向到,但我看到路由错误
No route matches {:action=>"show", :controller=>"blogs"}
因为我看到了,所以很奇怪
blog GET /blogs/:id(.:format) {:controller=>"blogs", :action=>"show"}
在耙路径上
任何想法-什么可能导致以下错误?似乎没有设置父项(blog),因为它不在routes参数中。
您是否已将所属对象添加到PostsController
PostsController < InheritedResources::Base
belongs_to :blog
...
PostsController
当然可以!!!我试图将动作“blogs#show”和“posts#index”与所描述的代码结合起来。也许你们知道更好的方法?我已经改变了我的资源路径:blogs,:except=>[:show]do resources:posts end match'blogs/:blog_id'=>'posts#index',但不确定这是否是最好的解决方案