Answer question through ajax
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
//= require markdown_editor
|
||||
//= require cocoon
|
||||
//= require allegations
|
||||
//= require legislation_questions
|
||||
//= require custom
|
||||
|
||||
var initialize_modules = function() {
|
||||
@@ -74,6 +75,7 @@ var initialize_modules = function() {
|
||||
App.SocialShare.initialize();
|
||||
App.MarkdownEditor.initialize();
|
||||
App.Allegations.initialize();
|
||||
App.LegislationQuestions.initialize();
|
||||
};
|
||||
|
||||
$(function(){
|
||||
|
||||
8
app/assets/javascripts/legislation_questions.js.coffee
Normal file
8
app/assets/javascripts/legislation_questions.js.coffee
Normal file
@@ -0,0 +1,8 @@
|
||||
App.LegislationQuestions =
|
||||
|
||||
initialize: ->
|
||||
$('form#new_legislation_answer input.button').hide()
|
||||
$('form#new_legislation_answer input[type=radio]').on
|
||||
click: ->
|
||||
$('form#new_legislation_answer').submit()
|
||||
|
||||
@@ -6,10 +6,16 @@ class Legislation::AnswersController < Legislation::BaseController
|
||||
load_and_authorize_resource :question, through: :process
|
||||
load_and_authorize_resource :answer, through: :question
|
||||
|
||||
respond_to :html, :js
|
||||
|
||||
def create
|
||||
@answer.user = current_user
|
||||
@answer.save
|
||||
redirect_to legislation_process_question_path(@process, @question)
|
||||
|
||||
respond_to do |format|
|
||||
format.js {}
|
||||
format.html { redirect_to legislation_process_question_path(@process, @question) }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
1
app/views/legislation/answers/create.js.erb
Normal file
1
app/views/legislation/answers/create.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#legislation-answer-form").html('<%= j render("legislation/questions/answer_form", process: @process, question: @question, answer: @answer) %>');
|
||||
12
app/views/legislation/questions/_answer_form.html.erb
Normal file
12
app/views/legislation/questions/_answer_form.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<% if question.question_options.any? %>
|
||||
<%= form_for answer, url: legislation_process_question_answers_path(process, question, answer), remote: true , html: { class: "controls-stacked participation-allowed"} do |f| %>
|
||||
<% question.question_options.each do |question_option| %>
|
||||
<label class="control radio <%= 'active' if @answer.legislation_question_option_id == question_option.id %>">
|
||||
<%= f.radio_button :legislation_question_option_id, question_option.id, label: false, disabled: answer.persisted? %>
|
||||
<span class="control-indicator"></span>
|
||||
<%= question_option.value %>
|
||||
</label>
|
||||
<% end %>
|
||||
<%= f.submit t('legislation.questions.show.answer_question'), class: "button" unless answer.persisted? %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@@ -22,19 +22,8 @@
|
||||
<div class="row">
|
||||
<div class="small-12 medium-9 column">
|
||||
<h3 class="quiz-question"><%= @question.title %></h3>
|
||||
<div class="debate-questions">
|
||||
<% if @question.question_options.any? %>
|
||||
<%= form_for @answer, url: legislation_process_question_answers_path(@process, @question, @answer), class: "controls-stacked" do |f| %>
|
||||
<% @question.question_options.each do |question_option| %>
|
||||
<label class="control radio <%= 'active' if @answer.legislation_question_option_id == question_option.id %>">
|
||||
<%= f.radio_button :legislation_question_option_id, question_option.id, label: false, disabled: @answer.persisted? %>
|
||||
<span class="control-indicator"></span>
|
||||
<%= question_option.value %>
|
||||
</label>
|
||||
<% end %>
|
||||
<%= f.submit t('.answer_question'), class: "button" unless @answer.persisted? %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<div class="debate-questions" id="legislation-answer-form">
|
||||
<%= render 'answer_form', process: @process, question: @question, answer: @answer %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user