Skip to content

Commit

Permalink
Update HasMany show collection partial path (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhippenmeyer authored and jordan-brough committed Dec 9, 2021
1 parent 1ca2ccf commit 2052d64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/fields/has_many/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ from the associated resource class's dashboard.
<% order = field.order_from_params(params.fetch(field.name, {})) %>
<% page_number = params.fetch(field.name, {}).fetch(:page, nil) %>
<%= render(
"collection",
field.collection_partial(namespace),
collection_presenter: field.associated_collection(order),
collection_field_name: field.name,
page: page,
Expand Down
15 changes: 15 additions & 0 deletions lib/administrate/field/has_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ def associated_resource_options
end
end

def collection_partial(namespace)
partial = 'collection'
prefix = options[:class_name].try(:underscore).try(:pluralize) || name
view_paths = ActionView::PathSet.new(["app/views/#{namespace}"])
lookup_context = ActionView::LookupContext.new(view_paths)

resouce_template_exists = lookup_context.exists?(partial, [namespace, prefix], true)
return [namespace, prefix, partial].join('/') if resouce_template_exists

application_template_exists = lookup_context.exists?(partial, [namespace, '/'], true)
return [namespace, partial].join('/') if application_template_exists

['administrate', 'application', partial].join('/')
end

def selected_options
return if data.empty?

Expand Down

0 comments on commit 2052d64

Please sign in to comment.