Question

I am building a Project management with the following associations:

Project
  - Section
    - Milestone
      - Issue

Inside app/views/section/show.html.erb - I want to have the entire section's milestones and its related issues. For each milestone I want to have a different form to create a new associated issue.

This is how the view file looks like:

    <%= @section.title %>
    <% @milestones.each do |milestone| %>
    <div id="milestone">
    <%= milestone.info %>
    </div>
<% milestone.issues.each do |issue| %>
    <div id="issue">
         <p><%= issue.content %></p>
    </div>
<% end %>

At the end of each milestone I have the following form to add a new issue:

    <%= form_for([@project, milestone.issues.build], :url => project_section_milestone_issue_path ) do |f| %>
        <p>
            <%= f.text_field :content   %>
            <%= f.submit %>
        </p>
<% end %>

This is my routes.rb:

resources :projects do 
  resources :sections do
    resources :milestones do 
      resources :issues
    end
  end
end

The form doesn't work, the page (view file) itself doesn't load and errors with wrong path url. I'm guessing something is wrong either with the routes or with the assignment within the form_for method.

Was it helpful?

Solution

The problem was with the form_for statement.

With @Zippie's hint, I changed it to: <%= form_for([@project, @section, milestone, milestone.issues.build] ) do |f| %> and it fixed the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top