lib/scaffolding_extensions/helper.rb
def scaffold_association_links
        klass = @scaffold_class
        return '' if @scaffold_class.scaffold_associations.empty?
        read_only = @scaffold_associations_readonly
        show_edit = read_only ? :show : :edit
        so = @scaffold_object
        soid = so.scaffold_id
        default_action = @scaffold_options[:default_action]
        singular_name = @scaffold_options[:singular_name]
        return '' unless klass.scaffold_associations.any?{|a| klass.scaffold_show_association_links?(a)}
        content = '<h3 class="scaffold_associated_records_header">Associated Records</h3>'
        content << "<ul id='scaffolded_associations_#{singular_name}_#{soid}' class='association_links #{klass.scaffold_association_list_class}'>\n"
        klass.scaffold_associations.each do |association| 
          next unless klass.scaffold_show_association_links?(association)
          class_name = klass.scaffold_associated_name(association)
          human_name = klass.scaffold_associated_human_name(association)
          content << "<li>"
          content << scaffold_check_link(human_name, read_only, "#{default_action}_#{class_name}") 
          content << "\n "
          case klass.scaffold_association_type(association)
            when :one
              associated_record = klass.scaffold_associated_objects(association, so, :session=>scaffold_session)
              content << " - #{scaffold_check_link(associated_record.scaffold_name, false, "#{show_edit}_#{class_name}", :id=>associated_record.scaffold_id) if associated_record}</li>\n"
              next
            when :edit
              content << scaffold_check_link('(associate)', true, "edit_#{singular_name}_#{association}", :id=>soid) unless read_only
            when :new
              unless read_only
                associated_params = {}
                klass.scaffold_new_associated_object_values(association, so).each{|key, value| associated_params["#{class_name}[#{key}]"] = value}
                content << scaffold_check_link('(create)', true, "new_#{class_name}", associated_params)
              end
          end
          if (records = klass.scaffold_associated_objects(association, so, :session=>scaffold_session)).length > 0
            content << "<ul>\n"
            records.each do |associated|
              content << "<li>#{scaffold_check_link(associated.scaffold_name, false, "#{show_edit}_#{class_name}", :id=>associated.scaffold_id)}</li>\n"
            end
            content << "</ul>\n"
          end
          content << "</li>\n"
        end
        content << "</ul>\n"
      end
# Return a string containing associated objects and links (if they would work) to pages
# to manage those objects.
Return a string containing associated objects and links (if they would work) to pages
to manage those objects.
Return a string containing associated objects and links ( if they would work ) to pages to manage those objects .
def scaffold_association_links
        klass = @scaffold_class
        return '' if @scaffold_class.scaffold_associations.empty?
        read_only = @scaffold_associations_readonly
        show_edit = read_only ? :show : :edit
        so = @scaffold_object
        soid = so.scaffold_id
        default_action = @scaffold_options[:default_action]
        singular_name = @scaffold_options[:singular_name]
        return '' unless klass.scaffold_associations.any?{|a| klass.scaffold_show_association_links?(a)}
        content = '<h3 class="scaffold_associated_records_header">Associated Records</h3>'
        content << "<ul id='scaffolded_associations_#{singular_name}_#{soid}' class='association_links #{klass.scaffold_association_list_class}'>\n"
        klass.scaffold_associations.each do |association| 
          next unless klass.scaffold_show_association_links?(association)
          class_name = klass.scaffold_associated_name(association)
          human_name = klass.scaffold_associated_human_name(association)
          content << "<li>"
          content << scaffold_check_link(human_name, read_only, "#{default_action}_#{class_name}") 
          content << "\n "
          case klass.scaffold_association_type(association)
            when :one
              associated_record = klass.scaffold_associated_objects(association, so, :session=>scaffold_session)
              content << " - #{scaffold_check_link(associated_record.scaffold_name, false, "#{show_edit}_#{class_name}", :id=>associated_record.scaffold_id) if associated_record}</li>\n"
              next
            when :edit
              content << scaffold_check_link('(associate)', true, "edit_#{singular_name}_#{association}", :id=>soid) unless read_only
            when :new
              unless read_only
                associated_params = {}
                klass.scaffold_new_associated_object_values(association, so).each{|key, value| associated_params["#{class_name}[#{key}]"] = value}
                content << scaffold_check_link('(create)', true, "new_#{class_name}", associated_params)
              end
          end
          if (records = klass.scaffold_associated_objects(association, so, :session=>scaffold_session)).length > 0
            content << "<ul>\n"
            records.each do |associated|
              content << "<li>#{scaffold_check_link(associated.scaffold_name, false, "#{show_edit}_#{class_name}", :id=>associated.scaffold_id)}</li>\n"
            end
            content << "</ul>\n"
          end
          content << "</li>\n"
        end
        content << "</ul>\n"
      end
def scaffold_association_links klass = @scaffold_class return '' if @scaffold_class . scaffold_associations . empty? read_only = @scaffold_associations_readonly show_edit = read_only ? :show : :edit so = @scaffold_object soid = so . scaffold_id default_action = @scaffold_options [ :default_action ] singular_name = @scaffold_options [ :singular_name ] return '' unless klass . scaffold_associations . any? { | a | klass . scaffold_show_association_links? ( a ) } content = '<h3 class="scaffold_associated_records_header">Associated Records</h3>' content << "<ul id='scaffolded_associations_#{singular_name}_#{soid}' class='association_links #{klass.scaffold_association_list_class}'>\n" klass . scaffold_associations . each do | association | next unless klass . scaffold_show_association_links? ( association ) class_name = klass . scaffold_associated_name ( association ) human_name = klass . scaffold_associated_human_name ( association ) content << "<li>" content << scaffold_check_link ( human_name , read_only , "#{default_action}_#{class_name}" ) content << "\n " case klass . scaffold_association_type ( association ) when :one associated_record = klass . scaffold_associated_objects ( association , so , :session => scaffold_session ) content << " - #{scaffold_check_link(associated_record.scaffold_name, false, "#{show_edit}_#{class_name}", :id=>associated_record.scaffold_id) if associated_record}</li>\n" next when :edit content << scaffold_check_link ( '(associate)' , true , "edit_#{singular_name}_#{association}" , :id => soid ) unless read_only when :new unless read_only associated_params = { } klass . scaffold_new_associated_object_values ( association , so ) . each { | key , value | associated_params [ "#{class_name}[#{key}]" ] = value } content << scaffold_check_link ( '(create)' , true , "new_#{class_name}" , associated_params ) end end if ( records = klass . scaffold_associated_objects ( association , so , :session => scaffold_session ) ) . length > 0 content << "<ul>\n" records . each do | associated | content << "<li>#{scaffold_check_link(associated.scaffold_name, false, "#{show_edit}_#{class_name}", :id=>associated.scaffold_id)}</li>\n" end content << "</ul>\n" end content << "</li>\n" end content << "</ul>\n" end
Return a string containing associated objects and links (if they would work) to pages
to manage those objects.
Return a string containing associated objects and links ( if they would work ) to pages to manage those objects .