Subselection by URL

Hey guys,
I’m quite new in RoR, so please excuse me when I may ask weird
questions.

I am working on a database frontend. The layout looks mostly like
a has_many bs
b has_many cs
c has_many ds
and so on. Now I want to do some selection. Maybe I want to see all ds
belonging to a specific b. I would like to do it like:
http://my.host/bs/1/ds
When I click around there (add new ds, show a d or whatever), I would
like to keep that b, so I always get like /bs/1/d/new and end up in
/bs/1/ds again.
Now comes the tricky part. I also want to have the same behavior for
/as/1/ds and /cs/1/ds. When possible even for /as/1/cs/3/ds.
I could do this by creating every route manually and touching every
link, at least I know how to create the link for show (just [@b, d]), I
would probably figure out how to create the other ones. But as I know
RoR, there should be an easier way to do this. Surprisingly, I did not
yet find one, so maybe you can give me hints how this could be done.

Thanks!

Jo Bu wrote in post #969496:

Hey guys,
I’m quite new in RoR, so please excuse me when I may ask weird
questions.

I am working on a database frontend. The layout looks mostly like
a has_many bs
b has_many cs
c has_many ds
and so on. Now I want to do some selection. Maybe I want to see all ds
belonging to a specific b. I would like to do it like:
http://my.host/bs/1/ds

You want nested resources. Read the routing docs.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Sent from my iPhone

Have a look at GitHub - jamesgolick/resource_controller: Rails RESTful controller abstraction plugin.
It won’t solve all your problems, but some.

Simon Baumgartner wrote in post #969774:

Have a look at GitHub - jamesgolick/resource_controller: Rails RESTful controller abstraction plugin.

That looks very helpful, thank you!

Marnen Laibow-Koser wrote in post #969567:

You want nested resources. Read the routing docs.

Well yes, I could do that, but it would become very confusing. But I
would more like a solution like (in pseudocode)
if (URL matches “/a/:a_id/!(create|new|show|edit).*”)
set @a=A.find_by_id(:a_id)
Is that possible?
And then I would have to rewrite link_to to prefix with the given
values, right?