Has anyone come across this error before? I've looked online and couldn't find much information, perhaps I didn't render my JSON correctly?
Missing template answer/results, application/results with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder]}. Searched in: * "/Users/Minhaj/Desktop/my_survey/my_survey/app/views" * "/Users/Minhaj/.rvm/gems/ruby-2.4.1/gems/devise-4.5.0/app/views"
Here is the code. If there is an error, help will be appreciated in fixing it.
def create
@answer = current_survey.answers.create(question_id: question, choice_id: choice)
redirect_to question_survey_path(current_survey)
end
def results
@choices = choices_hash
@results = questions.map do |question|
{
question.question => CountChoicesService.call(question.id)
}
end
respond_to do |format|
format.html { render :nothing => true, :status => 204 }
format.json { render json: @results }
end
end
private
def question
@question ||= params[:question]
end
def choice
@choice ||= params[:choice]
end
def choices
@choices ||= Array.wrap(Choice.all)
end
def choices_hash
choices_hash = {}
choices.each { |choice| choices_hash[choice.id] = choice.choice }
choices_hash
end
def questions
@questions ||= Array.wrap(Question.all)
end
end
I appreciate the help in advance.
viewnamedresults.html.erbunderanswersnamespace. You should have a directory structure like thisapp/views/answers/, go inside that and createresults.html.erb- Kedarnag Mukanahallipatnaredirectin theresultsaction, or create a view like I explained above. Usually, we redirect on success. - Kedarnag Mukanahallipatnaanswersit'sanswer.Change it toanswers- Kedarnag Mukanahallipatna