Alain Ravet
2006-Nov-01 23:22 UTC
nesting REST resources => scaffolded code requires heavy patching
When you nest REST resources,
ex:
map.resources :articles do |article|
article.resources :comments
end
the scaffold_resource generated code has to be manually edited to add
the parent id in about 15 locations accross 5 files of the child (the 4
views and the controller).
Most of the time, you must just replace
comment_path(comment)
by
comment_path(@article, comment)
, but
- in new.rhtml you need to add a hidden field, and
<%= f.hidden_field :article_id , :value => @article.id%>
- in the controller you also have to add a filter to fetch the parent
before_filter :load_article
def load_article
@article= Article.find params[:article_id]
end
********
Question: Am I doing something wrong/is there a simpler way?
********
(note: I noticed that some xxx_path() can be left untouched, but as my
next step will be to try using REST with polymorphic association, I
tried to be consistent and I fixed them all).
Alain
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---