Last active
July 11, 2016 20:35
-
-
Save Frank004/2434c8186eb21f66bd401ada3fd6e926 to your computer and use it in GitHub Desktop.
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
<%= form_for([@project, @survey], :html => { :class => 'form' })do |f| %> | |
<%= f.collection_select :survey_builder_id, SurveyBuilder.all, :id, :name, :include_blank => "Seleccione Plantilla"},class: 'select2'%> | |
<%= f.submit class: 'btn btn-success' %> | |
<% end %> |
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
get 'surveys/show_questions', as: 'show_questions' |
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
$('#temp_questions').html("<%= j render partial: 'question_builder', locals: {question: @question } %>"); |
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
$(document).ready(function(){ | |
$(function() { | |
return $(document).on('change', '#survey_survey_builder_id', function(evt) { | |
var builder = $('#survey_survey_builder_id option:selected').val(); | |
if(builder == ''){ | |
$('#temp_questions').empty() | |
} else { | |
return $.ajax('show_questions', { | |
type: 'GET', | |
dataType: 'script', | |
data: { | |
survey_builder_id: builder | |
}, | |
error: function(jqXHR, textStatus, errorThrown) { | |
return console.log("AJAX Error: " + textStatus); | |
}, | |
success: function(data, textStatus, jqXHR) { | |
return console.log("Dynamic Survey Builder select OK!"); | |
} | |
}); | |
} | |
}); | |
}); | |
}); |
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
class SurveysController < ApplicationController | |
def show_questions | |
@survey_builder = SurveyBuilder.find(params[:survey_builder_id]) | |
@questions = @survey_builder.question_builders | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment