Last active
August 29, 2015 14:14
-
-
Save mattdvhope/9aec8eb362e7b4eb51ac to your computer and use it in GitHub Desktop.
Question about rendering response to ajax request.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
[email protected] 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