Skip to content

Commit

Permalink
Update HasMany show collection partial path
Browse files Browse the repository at this point in the history
  • Loading branch information
nhippenmeyer committed Apr 27, 2020
1 parent bd45abf commit 8216f44
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 @@ -25,6 +25,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 8216f44

Please sign in to comment.