Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 继承的_资源-转到父级_Ruby On Rails_Ruby_Ruby On Rails 3_Inherited Resources - Fatal编程技术网

Ruby on rails 继承的_资源-转到父级

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

我有2个继承的资源(带有Jose Valim插件)-博客和帖子。当然-博文hm博文和博文bt博文。路线就足够了

  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',但不确定这是否是最好的解决方案