Hi François,
I understand your case, it’s ok, but it is not exactly what I mean.
What about this:
class Person < AR::B
has many :phones
end
class Phone < AR::B
belongs_ot :person
end
class Customer < Person
end
Class Friend < Person
end
I have this in routes.rb
map.resources :people do |person|
person.resources :phones, name_prefix => “person_”
end
map.resources :customers do |customer|
customer.resources :phones, name_prefix => “customer_”
end
map.resources :friends do |friend|
friend.resources :phones, name_prefix => “friend_”
end
Now I can have these urls, nesting the phone resource in both customer
and friend resources:
/customer/1/phone/1
/friend/2/phone/3
I think this works well and go with the flow but, then, in the phone
controller, and the associated views, I would like to have a smart way
of knowing the type of the parent resource, and be capable of using a
named route to it, but I have to resort to make use of person[:type] in
a case sentence and use named paths like person_edit_phone_path, or
person_phone_path.
Oh well, now, writing it, it doesn’t look so bad.
The name_prefix is a necessity for avoiding urls collisions, and I
always will need a case sentence in the controller for redirecting to
the index view after a successful creation, update or destroy to
customer_path or friend_path based on person[:type]
I will leave the comment, maybe it can help someone.
Juanma