Created
August 14, 2018 04:01
-
-
Save itssomething/0350c166e8c581981526636f39be0b45 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
// This is a manifest file that'll be compiled into application.js, which will include all the files | |
// listed below. | |
// | |
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's | |
// vendor/assets/javascripts directory can be referenced here using a relative path. | |
// | |
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the | |
// compiled file. JavaScript code in this file should be added after the last require_* statement. | |
// | |
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details | |
// about supported directives. | |
// | |
//= require rails-ujs | |
//= require activestorage | |
//= require turbolinks | |
//= require_tree . | |
//= require jquery3 | |
//= require popper | |
//= require bootstrap-sprockets | |
$(document).on("turbolinks:load", function() { | |
$("form").on("click", ".add_fields", function(event) { | |
var regexp, time; | |
time = new Date().getTime(); | |
regexp = new RegExp($(this).data("id"), "g"); | |
$(".fields").append($(this).data("fields").replace(regexp, time)); | |
return event.preventDefault() ; | |
}); | |
$("form").on("click", ".remove_record", function(event) { | |
$(this).prev("input[type=hidden]").val("1"); | |
$(this).closest("div.step").hide(); | |
return event.preventDefault() ; | |
}); | |
}); |
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
module ApplicationHelper | |
def link_to_add_row name, form, association, **args | |
new_object = form.object.send(association).klass.new | |
id = new_object.object_id | |
fields = form.fields_for(association, new_object, child_index: id) do |b| | |
render(association.to_s.singularize, f: b) | |
end | |
link_to(name, "#", class: "add_fields " + args[:class], | |
data: {id: id, fields: fields.delete("\n")}) | |
end | |
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
<div class="row"> | |
<div class="col-md-6 offset-md-3"> | |
<%= form_for @question_bank do |f| %> | |
<%= f.label :name, t(".name"), class: "field-label" %> | |
<%= f.text_field :name, class: "form-control field-input" %> | |
<%= f.label :category, t(".category"), class: "field-label" %> | |
<h5>Add questions</h5> | |
<div> | |
<%= f.fields_for :questions do |ff| %> | |
<%= render "question", f: ff %> | |
<% end %> | |
</div> | |
<%= link_to_add_row(t(".add_question"), f, :questions, class: "btn btn-default") %> | |
<%= f.submit t(".submit"), class: "btn btn-primary submit-button" %> | |
<% end %> | |
</div> | |
<div> |
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
<div class = "question"> | |
<%= f.label :content, t(".content_question"), class: "field-label question-label" %> | |
<%= f.text_field :content, class: "form-control field-input" %> | |
<div> | |
<%= f.label :multi_correct, t(".multi"), class: "field-label" %> | |
<%= f.check_box :multi_correct, {}, "yes", "no" %> | |
</div> | |
<%= f.fields_for :answers do |ff| %> | |
<%= render "answer", f: ff %> | |
<% end %> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment