Module: Polygallery::SimpleFormHelper

Defined in:
lib/polygallery/simple_form_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.simple_fields_for_polygallery(fb, title = :gallery, *args, &block) ⇒ Object



6
7
8
9
# File 'lib/polygallery/simple_form_helper.rb', line 6

def self.simple_fields_for_polygallery(fb, title=:gallery, *args, &block)
  ( '<div class="polygallery-fields">' <<
      fb.simple_fields_for(title, *args, &block) << '</div>' ).html_safe
end

Instance Method Details

#simple_fields_for_polygallery(fb, title = :gallery, *args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/polygallery/simple_form_helper.rb', line 10

def simple_fields_for_polygallery(fb, title=:gallery, *args, &block)
  defaults = {
    label: nil,
    add_btn: {
      text: 'Add Photo',
      partial: 'polygallery/photos/simple_fields_for',
      class: 'btn btn-default btn-sm pull-right',
      data: { association_insertion_method: 'append',
              association_insertion_node: "##{fb.object.send(title).polygallery_settings[:association_names][:photos]} .photo-receptacle" }},
    remove_btn: { class: 'btn btn-default btn-sm' },
    file_input: {}}
  settings = if (options = args.find{|a| a.is_a? Hash }).nil? then defaults
             else defaults.deep_merge options end
  new_block = block_given? ? block : ->(fb2) {
    render partial: 'polygallery/galleries/simple_fields_for',
           locals: { f: fb2, settings: settings } }
  SimpleFormHelper.simple_fields_for_polygallery(
    fb, title, *args, &new_block)
end