I’ve written a little plugin – consisting entirely of modifications
to define_url_helper in ActionController – which will infer nested
named RESTful route components from one object.
For example, given a nest like this:
map.resources :schools do |s|
s.resources :departments do |d|
d.resources :teachers
end
end
I’ve written a little plugin – consisting entirely of modifications
to define_url_helper in ActionController – which will infer nested
named RESTful route components from one object.
I’ve made it a little less hackerly by putting the code in lib/ rather
than in init.rb Nothing else has changed, but if you want to have
a version that’s a bit more well-behaved in its code organization, you
can get:
one more question before you put your sword to rest : what about
polymorphic associations?
map.resources :articles do |article|
article.resources :comments
end
map.resources :photos do |photo|
photo.resources :comments
end
In this case,
comments_url(@comment)
should translate to something like
comments_url(@comment.commentable_id, @comment)
(?? and what about the 'commentable_type)
I must confess I’m a REST newbie, so I’m not sure at all REST can work
with polymorphism.
Alain
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.