0

i have 2 inherited resources (with plugin of Jose Valim) - Blogs and Posts. Of course - Blog hm Posts and Post bt Blog. Routes is simply enough

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

Also i have updated action posts#index with following

  def index
    redirect_to parent_url
  end

as i have planned - on attempt to access http://devhost/blogs/2/posts i will be redirected to http://devhost/blogs/2, but i see routing error

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

its so strange because i see

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

on rake routes.

Any idea - what may cause following error?

1 Answer 1

0

It seems the parent(blog) isn't set because it isn't present in the routes params. Did you add the belongs_to to the PostsController?

PostsController < InheritedResources::Base
  belongs_to :blog
  ...
2
  • yes, of course!!! i'm trying to combine actions 'blogs#show' and 'posts#index' with described piece of code. maybe you know better way? Nov 22, 2010 at 21:02
  • i have changed my routes to resources :blogs, :except => [:show] do resources :posts end match 'blogs/:blog_id' => 'posts#index' but not sure that it is the best solution Nov 22, 2010 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.