Rails - Simple Form & Nesting models

52 views Asked by At

I have three models in my Rails 4 app.

I have a projects, project questions and a project answers model.

Projects

has_many :project_questions, dependent: :destroy#, through: :projects
accepts_nested_attributes_for :project_questions

Project questions has these associations:

  belongs_to :project#, counter_cache: true
  has_many :project_answers, dependent: :destroy
  belongs_to :user
  accepts_nested_attributes_for :project_answers

Project answers associations are:

 belongs_to :project_question#, counter_cache: true  
belongs_to :user 

My routes.rb has:

  resources :projects do
  # patch '/toggle-draft', to 'projects#toggle_draft', as: 'toggle_draft'
    resources :project_questions do
      resources :project_answers
    end
  end

In my projects_controller, I have permitted params for project questions and answers as follows:

 project_question_attributes: [:title, :content, :user_id, :project_id,
      project_answer_attributes: [:answer, :project_question_id]],

These params are also permitted in the Project questions and project answers controllers.

In my projects view, I want to render a partial that I have made in my project_questions view folder.

In projects show page, I have:

  <%= link_to 'Ask a question', new_project_question_path %> <% end %>
  <%= render 'project_questions/pqps' %>

In my project_questions partial which is called _pqps, I have;

<div class="containerfluid">
  <div class="row">
    <div class="col-md-10 col-md-offset-1">

      <% f.simple_fields_for :project_questions, @project.project_questions.build do |q| %>
          <div class="categorytitle">
            <%= q.title %>
          </div>
          <div class="generaltext">
            <%= q.content %>
          </div>
          <%= render 'project_answers/show' %>
          <span class="editproject">   <% if current_user.id ==  @project.creator_id %>
            <%= link_to 'Answer this question', new_project_answer_path %>
              <% end %>
          </span>

      <% end %>
    </div>
  </div>
</div>

However, when I try this, I get an error that says:

undefined local variable or method `new_project_question_path'

Can anyone see what i've done wrong?

Thank you

0

There are 0 answers