Last active
August 29, 2015 13:56
Revisions
-
ogryzek revised this gist
Feb 27, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,8 +5,8 @@ def link_to_add_fields(anchor_text, form_object, association) new_nested_object = form_object.object.send(association).new id = new_nested_object.object_id field_html = form_object.fields_for(association, new_nested_object, child_index: id) do |ff| render(association.to_s.singularize + "_fields", f: ff) end link_to(anchor_text, "javascript:void(0);", class: "add_fields", -
ogryzek revised this gist
Feb 27, 2014 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ $(document).on "click", "form .add_fields", -> time = new Date().getTime() regex = new RegExp($(this).data("id"), "g") item_fields_html = $(this).data("field-html").replace(regex, time) $(this).before(item_fields_html) -
ogryzek revised this gist
Feb 27, 2014 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ module ApplicationHelper def link_to_add_fields(anchor_text, form_object, association) new_nested_object = form_object.object.send(association).new id = new_nested_object.object_id field_html = form_object.fields_for(association, new_nested_object, child_index: id) do |option| render(association.to_s.singularize + "_fields", f: option) end link_to(anchor_text, "javascript:void(0);", class: "add_fields", data: {id: id, field_html: field_html.gsub("\n", "")}) end end -
ogryzek revised this gist
Feb 27, 2014 . 1 changed file with 25 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ = form_for(@question) do |f| - if @question.errors.any? #error_explanation %h2 = pluralize(@question.errors.count, "error") prohibited this question from being saved: %ul - @question.errors.full_messages.each do |msg| %li= msg .field = f.label :title %br = f.text_field :title .field = f.label :body %br = f.text_area :body %h3 Options = f.fields_for :options do |opt| = render "option_fields", f: opt = link_to_add_fields "Add Option", f, :options %br = f.submit -
ogryzek created this gist
Feb 27, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ %fieldset.answer = f.label :title = f.text_field :title = f.label :body = f.text_field :body = f.check_box :_destroy = f.label :_destroy %br