Nesting REST resources => scaffolded code requires heavy pat

When you nest REST resources,
map.resources :articles do |article|
article.resources :comments

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(@article, comment)
, but

  • in new.rhtml you need to add a hidden field, and
    <%= f.hidden_field :article_id , :value =>>

  • 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]

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).


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs