Forum: Ruby on Rails Parent::Children controller

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5b80dc22abd5e73520a44cc5c41b172b?d=identicon&s=25 Klaus Paiva (Guest)
on 2006-12-31 10:31
Hello!

I'm creating a simple blog to test RoR. I've created an area to manage
my blog posts by using the "generate controller Admin::Posts". After
creating my actions, I can acess them by using:

http://localhost:3000/admin/posts/action_here

Everything working till here. But I would like to display a blog
overview here:

http://localhost:3000/admin/

So I've created an admin controller: "generate controller Admin" and an
"index" action. The new index action works but, the previous
posts/action_here not anymore.

I think that when I put /admin/posts on the URL and the controller admin
exists, I need to tell that I want to use the posts_controller, not the
admin_controller. Someone knows how can I do that?

Or if someone has a better idea to implement this I'll be grateful!

Thanks for your attention!
86e084334c00a932a3675adbf769de67?d=identicon&s=25 Paul Corcoran (Guest)
on 2007-01-01 19:55
(Received via mailing list)
Klaus,

You are correct in thinking that the admin/admin.rb file is screwing
things up. Nested controllers seem to work best when you split your
controllers in groups like: admin/xxx and admin/yyy. Your controllers
would then be under xxx or yyy but not split with some being directly
under admin. You need no special routing configuration to accomodate
this.

Perhaps your best solution right now is to just forget about nesting
the controllers and have it all under admin until you can see how
changing this structure would serve you better.

-Paul
380297e841aa0b1345b87d34638b915e?d=identicon&s=25 Klaus Paiva (Guest)
on 2007-01-03 13:00
(Received via mailing list)
Hi Paul,
thanks for your help!

I've found something useful on the book: - It's about the
config/routes.rb. In this file I can define when to use the post
controller by adding these lines:

# Admin::Posts
map.admin_posts 'admin/posts/:action/:id',
  :controller => 'admin/posts',
  :requirements => {
    :id => /\d+/
  }

That's it!
5b80dc22abd5e73520a44cc5c41b172b?d=identicon&s=25 Klaus Paiva (Guest)
on 2007-01-03 13:00
Hi Paul,
thanks for your help!

I've found something useful on the book: Agile Web Development with
Rails - It's about the config/routes.rb. In this file I can define when
to use the post controller by adding these lines:

# Admin::Posts
map.admin_posts 'admin/posts/:action/:id',
  :controller => 'admin/posts',
  :requirements => {
    :id => /\d+/
  }

That's it!
380297e841aa0b1345b87d34638b915e?d=identicon&s=25 Klaus Paiva (Guest)
on 2007-01-03 13:04
(Received via mailing list)
I forgot to paste the book name. :D

"Agile Web Development with Rails"
This topic is locked and can not be replied to.