Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/administrate/field/nested_has_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require "administrate/version"
require "cocoon"

require "administrate/page/nested_collection"

module Administrate
module Field
class NestedHasMany < Administrate::Field::HasMany
Expand Down Expand Up @@ -32,6 +34,12 @@ def nested_fields
end
end

def nested_attributes
associated_dashboard.collection_attributes.reject do |nested_attribute|
skipped_fields.include?(nested_attribute)
end
end

def nested_fields_for_builder(form_builder)
return nested_fields unless form_builder.index.is_a? Integer

Expand Down Expand Up @@ -86,6 +94,10 @@ def association_name
end
end

def associated_collection(order = self.order)
Administrate::Page::NestedCollection.new(associated_dashboard, order: order, collection_attributes: nested_attributes)
end

def associated_form
Administrate::Page::Form.new(associated_dashboard, new_resource)
end
Expand Down
11 changes: 11 additions & 0 deletions lib/administrate/page/nested_collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'administrate/page/collection'

module Administrate
module Page
class NestedCollection < Page::Collection
def attribute_names
options.fetch(:collection_attributes, dashboard.collection_attributes)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the following? That way you only call dashboard.collection_attributes lazily, when there is no :collection_attributes available:

Suggested change
options.fetch(:collection_attributes, dashboard.collection_attributes)
options.fetch(:collection_attributes) { dashboard.collection_attributes }

end
end
end
end