1

Sorry, this is a naive question.

I have a nested resources depth 2 levels.

  resources :programs do  
    resources :questions do
      resources :answers
    end
  end

So for the index,edit, etc pages to work I need to modify the link_to attribute for show, edit, new buttons in the views.

For eg,

<%= link_to 'Show', edit_question_path %>

How should I rename this edit_question_path to? Should it be edit_question_program_path or it should be edit_program_question_path. I am confused of this convention, if we have programs->questions-> answers, then how should the convention be in the link_to's path?. Please help

Clone
  • 919
  • 4
  • 11
  • 22

1 Answers1

1

To know which route to use, just fire rake routes to see the right path name.

Also, in this case you need to supply three objects for link_to

link_to "Something", 
  edit_program_question_answer_path(@program, @question, @answer)

Isn't that ugly? Lots of works to do to feed link_to alone, and there will be more.

Don't abuse nested resources. Never use them over 2 in my opinion. I myself prefer to avoid nested resource at all when possible.

Billy Chan
  • 24,625
  • 4
  • 52
  • 68
  • Thanks for the quick response, so how should I redesign my models,routes in order to make them less cumbersome? – Clone Jun 16 '13 at 18:50
  • @Clone, this does nothing with models, just the routes. You can give each model a separate resource when nested resource is not a must. You can check http://guides.rubyonrails.org/routing.html for more. – Billy Chan Jun 16 '13 at 18:54