title: Rails: How to render a nested partial
body: <p>I am trying to make an app with Rails 4 and Simple Form.</p>
  
  <p>I have a projects model, a project_questions model and a project answer model.</p>
  
  <p>The associations are:</p>
  
  <p>Project.rb:</p>
  
  <pre><code>   has_many :project_questions, dependent: :destroy#, through: :projects
    accepts_nested_attributes_for :project_questions
  </code></pre>
  
  <p>Project_question.rb:</p>
  
  <pre><code>belongs_to :project#, counter_cache: true
    has_one :project_answer, dependent: :destroy
    belongs_to :user
    accepts_nested_attributes_for :project_answer
  </code></pre>
  
  <p>Project answer.rb:</p>
  
  <pre><code>  belongs_to :project_questions#, counter_cache: true
    belongs_to :user
  </code></pre>
  
  <p>My routes are nested:</p>
  
  <pre><code>  resources :projects do
      resources :project_questions do
        resources :project_answers
      end
    end
  </code></pre>
  
  <p>My project show, includes a partial to show questions asked about the project.</p>
  
  <pre><code>  &lt;%= render 'project_questions/pqps' %&gt;
  </code></pre>
  
  <p>Inside that project-question partial(pqps), I am trying to render the project answers partial so that the answer sits beneath the question.</p>
  
  <pre><code>  &lt;% @project.project_questions.each do |singleQuestion| %&gt;
  
        &lt;div class="categorytitle"&gt;
          &lt;%= singleQuestion.title %&gt;
  
        &lt;/div&gt;
        &lt;div class="generaltext"&gt;
          &lt;%= singleQuestion.try(:content) %&gt;
        &lt;/div&gt;
        &lt;span class="editproject"&gt;
          &lt;% if current_user.id == @project.creator_id %&gt;
  
              &lt;%= link_to 'Answer this question', new_project_project_question_project_answer_path(:project_id =&gt; @project.id, :project_question_id =&gt; singleQuestion.id) %&gt;
  &lt;% else %&gt;
              &lt;%= render 'project_answers/answers' %&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>I'm struggling, because the code I have in the project_answer partial view is:</p>
  
  <pre><code>        &lt;%= @project.project_questions.project_answers.answer %&gt;
  </code></pre>
  
  <p>When I try this, I get this error:</p>
  
  <pre><code>undefined method `project_answers' for #`&lt;ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_ProjectQuestion:0x000001039ebcc8&gt;`
  </code></pre>
  
  <p>I have tried all forms and combinations of pluralising different bits of that project answer line of code, but nothing works.</p>
  
  <p>When I try the answer as: 
              &lt;%= @project.project_questions.project_answer.answer %></p>
  
  <pre><code>undefined method `project_answer' for #&lt;ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_ProjectQuestion:0x00000102b59318&gt;
  </code></pre>
  
  <p>I don't understand why that is.</p>
  
  <p>In my project answer controller, I have:</p>
  
  <pre><code>class ProjectAnswersController &lt; ApplicationController
    before_action :set_project
    before_action :set_project_question
    before_action :set_project_answer, only: [:show, :edit, :update, :destroy]
  
  
    # GET /project_answers
    # GET /project_answers.json
    def index
      @project_answers = ProjectAnswer.all
    end
  
    # GET /project_answers/1
    # GET /project_answers/1.json
    def show
    end
  
    # GET /project_answers/new
  
  
    def new
      @project_answer = @project_question.build_project_answer
    end
  
    # GET /project_answers/1/edit
    def edit
    end
  
    # POST /project_answers
    # POST /project_answers.json
    def create
      @project_answer = @project_question.build_project_answer(project_answer_params)
  
  
      respond_to do |format|
        if @project_answer.save
          format.html { redirect_to @project, notice: 'Project answer was successfully created.' }
          format.json { render action: 'show', status: :created, location: @project_answer }
        else
          format.html { render action: 'new' }
          format.json { render json: @project_answer.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /project_answers/1
    # PATCH/PUT /project_answers/1.json
    def update
      respond_to do |format|
        if @project_answer.update(project_answer_params)
          format.html { redirect_to @project_answer, notice: 'Project answer was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: 'edit' }
          format.json { render json: @project_answer.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /project_answers/1
    # DELETE /project_answers/1.json
    def destroy
      @project_answer.destroy
      respond_to do |format|
        format.html { redirect_to project_answers_url }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
  
      def set_project
        @project = Project.find(params[:project_id])
      end
  
      def set_project_question
        @project_question = @project.project_questions.find(params[:project_question_id])
      end
  
  
    def set_project_answer
        @project_answer = ProjectAnswer.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def project_answer_params
        params[:project_answer].permit(:answer, :project_question_id, :id)
      end
  end
  </code></pre>
  
  <p>I had thought that was supposed to let me just use @project.answer.answer, but I have also tried that and it doesnt work either.</p>
  
  <p>Can anyone see what i need to do to render the answer to the question?</p>