Skip to content

Instantly share code, notes, and snippets.

@mattdvhope
Last active August 29, 2015 14:14
Show Gist options
  • Save mattdvhope/9aec8eb362e7b4eb51ac to your computer and use it in GitHub Desktop.
Save mattdvhope/9aec8eb362e7b4eb51ac to your computer and use it in GitHub Desktop.
Question about rendering response to ajax request.
# In this controller below, I removed the render :nothing & set up views/choices/update.js.erb
class ChoicesController < ApplicationController
before_action :require_user
def update
respond_to do |format|
format.js {
@choice = Choice.find(params[:id])
choices = @choice.question.choices.where(student_id: current_user.id)
choices.each do |choice|
choice.update_column(:selected, false)
choice.answer
end
@choice.update_column(:selected, true)
}
end
end
end
# views/choices/update.js.erb....
$('#question_<%= @choice.question.id %>').html("<%= j render partial: 'assessments/answers_to_each_question', :locals => { question: @choice.question } %>");
# views/assessments/show.html.haml.....
-i = 1
-@assessment.questions.each do |question|
%hr
%h3=i.to_s + ". " + question.question_content
%span{:id => "question_#{question.id}"}= render 'answers_to_each_question', :question => question
-i = i + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment