2010-11-21 55 views
0

我有2个继承资源(与何塞Valim插件) - 博客和帖子。当然 - 博客hm文章和博客bt博客。路线是根本不够inherited_resources - 去父母

resources :blogs, :only => [:show] do 
    resources :posts 
    end 

我也有更新的动作与以下

def index 
    redirect_to parent_url 
    end 

,因为我有计划的职位#指数 - 上试图访问http://devhost/blogs/2/posts我将被重定向到http://devhost/blogs/2,但我看到路由错误

No route matches {:action=>"show", :controller=>"blogs"} 

它太奇怪了,因为我看到

blog GET /blogs/:id(.:format)  {:controller=>"blogs", :action=>"show"} 

on 耙路线

任何想法 - 什么可能会导致以下错误?

回答

0

似乎父母(博客)没有设置,因为它不存在的路线PARAMS。 您是否将belongs_to添加到PostsController?

PostsController < InheritedResources::Base 
    belongs_to :blog 
    ... 
+0

是的,当然!!!我正在尝试将操作'博客#show'和'posts#index'与描述的代码片段结合起来。也许你知道更好的方法? – 2010-11-22 21:02:59

+0

我改变了路线 资源:博客:除了=> [:秀]做 资源:帖子 结束 匹配“博客/:blog_id” =>“帖子#指数” ,但不知道它是最好的解决方案 – 2010-11-22 21:21:02