I have a project with posts, comments and questions. The comments belong to a post and the questions belong to a comment. I am trying to show all the questions that belong to a comment on a page. However, the index page does not display any of the questions. It does not give an error but is just blank.
Here is my questions_controller.rb:
class QuestionsController < ApplicationController
before_action :set_question, only: [:show, :edit, :update, :destroy]
def index
@comment = Comment.find params[:comment_id]
@comment.questions
end
def show
end
def new
@comment = Comment.find params[:comment_id]
end
def edit
end
def create
@comment = Comment.find(params[:comment_id])
@question = @comment.questions.create(question_params)
respond_to do |format|
if @question.save
format.html { redirect_to comment_questions_path, notice: 'Question was successfully created.' }
format.json { render action: 'show', status: :created, location: comment_questions_path }
else
format.html { render action: 'new' }
format.json { render json: @question.errors, status: :unprocessable_entity }
end
end
end
The index file calls a _question.html.erb partial:
<%=div_for(@question) do %>
<%= @question.body %>
<% end %>
The index.html.erb file:
<%= render "questions/question" %>
And finally the link to the index page looks like this:
<%= link_to 'View Questions', comment_questions_path(comment)%>
I have checked and the questions are saving to the db so that's not the problem. I really appreciate any help.