lib/scaffolding_extensions/helper.rb
# Returns html fragment containing autocompleting text or select boxes to add associated records
# to the current record, and line items with buttons to remove associated records
# from the current record.
Returns html fragment containing autocompleting text or select boxes to add associated records
to the current record, and line items with buttons to remove associated records
from the current record.
Returns html fragment containing autocompleting text or select boxes to add associated records to the current record and line items with buttons to remove associated records from the current record .
def scaffold_habtm_ajax_associations
        klass = @scaffold_class
        return '' unless klass.scaffold_habtm_with_ajax
        sn = @scaffold_options[:singular_name]
        so = @scaffold_object
        soid = so.scaffold_id
        content = "<div class='habtm_ajax_add_associations' id='#{sn}_habtm_ajax_add_associations'>"
        klass.scaffold_habtm_associations.reject{|association| !scaffolded_method?("add_#{association}_to_#{sn}")}.each do |association|
          content << "#{scaffold_form_remote_tag("add_#{association}_to_#{sn}", :id=>soid)}\n#{scaffold_habtm_ajax_tag("#{sn}_#{association}_id", so, sn, association)}\n<input name='commit' class=\"btn btn-primary\" type='submit' value='Add #{klass.scaffold_associated_human_name(association).singularize}' /></form>\n"
        end
        content << "</div><div class='habtm_ajax_remove_associations' id='#{sn}_habtm_ajax_remove_associations'><ul id='#{sn}_associated_records_list'>"
        klass.scaffold_habtm_associations.reject{|association| !scaffolded_method?("remove_#{association}_from_#{sn}")}.each do |association|
          klass.scaffold_associated_objects(association, so, :session=>scaffold_session).each do |associated_record|
            content << scaffold_habtm_association_line_item(klass, association, @scaffold_object, associated_record)
          end
        end
        content << '</ul></div>'
        content
      end
def scaffold_habtm_ajax_associations klass = @scaffold_class return '' unless klass . scaffold_habtm_with_ajax sn = @scaffold_options [ :singular_name ] so = @scaffold_object soid = so . scaffold_id content = "<div class='habtm_ajax_add_associations' id='#{sn}_habtm_ajax_add_associations'>" klass . scaffold_habtm_associations . reject { | association | ! scaffolded_method? ( "add_#{association}_to_#{sn}" ) } . each do | association | content << "#{scaffold_form_remote_tag("add_#{association}_to_#{sn}", :id=>soid)}\n#{scaffold_habtm_ajax_tag("#{sn}_#{association}_id", so, sn, association)}\n<input name='commit' class=\"btn btn-primary\" type='submit' value='Add #{klass.scaffold_associated_human_name(association).singularize}' /></form>\n" end content << "</div><div class='habtm_ajax_remove_associations' id='#{sn}_habtm_ajax_remove_associations'><ul id='#{sn}_associated_records_list'>" klass . scaffold_habtm_associations . reject { | association | ! scaffolded_method? ( "remove_#{association}_from_#{sn}" ) } . each do | association | klass . scaffold_associated_objects ( association , so , :session => scaffold_session ) . each do | associated_record | content << scaffold_habtm_association_line_item ( klass , association , @scaffold_object , associated_record ) end end content << '</ul></div>' content end
Returns html fragment containing autocompleting text or select boxes to add associated records
to the current record, and line items with buttons to remove associated records
from the current record.
Returns html fragment containing autocompleting text or select boxes to add associated records to the current record and line items with buttons to remove associated records from the current record .