administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Model named "Template" won't show index in admin

Open darylpdavies opened this issue 3 years ago • 4 comments

If I visit http://localhost:3000/admin/templates/ I get the following error:

ArgumentError in Admin::TemplatesController#index
wrong number of arguments (given 1, expected 0)
Extracted source (around line #13):
resources = resources.page(params[:_page]).per(records_per_page)

But visiting a /show page within Templates works fine. Could this be a naming convention conflict as Administrate uses templates?

darylpdavies avatar Oct 28 '22 05:10 darylpdavies

do you add page or per function in app/models/template.rb?

jubilee2 avatar Oct 30 '22 02:10 jubilee2

@jubilee2 per function, but my Template model is relatively identical to my other models, it's just the only one where the index does not show.

darylpdavies avatar Oct 30 '22 06:10 darylpdavies

So rename the name of function from "pre" to others to fix the issue you have.

jubilee2 avatar Oct 30 '22 13:10 jubilee2

In part, this is a problem with Kaminari, which adds the page and per methods. As I understand your comment above, your models also have the method per, so this would cause a conflict. As mentioned, renaming per to something else is easiest fix at the moment.

As for the name "template", I don't see a reason why this should work differently. Administrate uses templates, but the name "template" is not used in any special way that I can see. Are you able to share a bit more about the exception that you see, and what your pre method does?

pablobm avatar Dec 13 '22 15:12 pablobm