Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination broken in 0.15 for customized views #1957

Closed
mmrobins opened this issue Apr 8, 2021 · 3 comments
Closed

Pagination broken in 0.15 for customized views #1957

mmrobins opened this issue Apr 8, 2021 · 3 comments
Labels
bug breakages in functionality that is implemented

Comments

@mmrobins
Copy link

mmrobins commented Apr 8, 2021

tl;dr the CHANGELOG.md should call out * [BUGFIX] [#1725] Fix pagination of "Page" models. as breaking pagination for customized views.

After I upgraded 0.14.0 -> 0.15.0 I started getting issues with pagination

I have config.action_controller.action_on_unpermitted_parameters = :raise, so started seeing errors

ActionView::Template::Error (found unpermitted parameter: :page):

I tried disabling that, but ended getting the page param stripped, so paging didn't work.

[2021-04-08T16:08:52.592-07:00] INFO: Request
{
  :method             => "GET",
  :path               => "/admin/myresource",
  :format             => :html,
  :controller         => "Admin::MyResoureController",
  :action             => "index",
  :status             => 200,
  :duration           => 107.39,
  :view               => 85.79,
  :db                 => 13.58,
  :unpermitted_params => [
    "page",
    "page",
    "page",
    "page"
  ],
  :request_id         => "cf594d02-436f-4bc2-8747-1b655a95c41d",
}

I finally tracked down the reason being #1725 changing the paging parameter from page to _page. This would be fine, but if you've customized your index.html.erb at all, you won't get the update to fix that rename.

My fix ended up being pretty, simple, just unexpected to need it

--- app/views/admin/application/index.html.erb
+++ app/views/admin/application/index.html.erb
@@ -70,5 +70,5 @@ It renders the `_table` partial to display details about the resources.
    table_title: "page-title"
  ) %>

-  <%= paginate resources %>
+  <%= paginate resources, param_name: '_page' %>
</section>

I looked through the CHANGELOG.md but didn't see anything that would have led me to expect this, so posting here in case anyone else bangs there head against this.

It would be great if versioning for this could bump to 1.0 so that future version bumps could use semver to communicate breaking changes more clearly. I get the project wants to be able to make breaking changes, but it seems mature enough that communicating that through semver would be pretty helpful.

Thanks for the taking the time to look through this, and for the great library.

@mmrobins mmrobins added the bug breakages in functionality that is implemented label Apr 8, 2021
@mmrobins mmrobins changed the title Pagination broken in 0.15 Pagination broken in 0.15 for customized views Apr 8, 2021
@pablobm
Copy link
Collaborator

pablobm commented Apr 16, 2021

Thank you for reporting @mmrobins. You are right that this is a breaking change and we should have communicated it.

In general, whenever we make changes to the default templates there's a chance that we'll introduce something that breaks custom templates. It's a difficult problem to solve, and particularly in this specific case I'm not sure it can be avoided at all, as there are several factors that we can't control.

Generally it's a good idea to check template changes when upgrading Administrate, but we should communicate it better. Perhaps we should list affected templates in the changelogs.

Unfortunately, I think that this specific bug doesn't really have a fix, beyond hoping that users will eventually all migrate and the problem will disappear. Therefore I'm going to close this issue, but I'm glad that you opened it in the first place, as it may help others.

@pablobm pablobm closed this as completed Apr 16, 2021
nickcharlton pushed a commit that referenced this issue May 10, 2021
Currently, it lists which template files have changed since the
version given as an argument (actually a Git tag):

```
$ ./bin/changelog v0.15.0
The following templates have changed since v0.15.0:

  app/views/administrate/application/_navigation.html.erb
  app/views/fields/url/_index.html.erb
  app/views/fields/url/_show.html.erb
```

If your application overrides any of them, make sure to review
your custom templates to ensure that they remain compatible.
This was inspired by #1957, where a user observed that it
would be worth mentioning these template updates in the 
changelog, as it's something that people need to look out for
when upgrading Administrate.
@AFlowOfCode
Copy link

Thank you for posting this @mmrobins and turning it into a quick fix. I expect things like this, but definitely agree that a list of affected templates or potentially breaking changes would be helpful for avoiding hunts through the codebase.

@pablobm
Copy link
Collaborator

pablobm commented Jun 24, 2021

Worth mentioning that we have starting doing this with templates. See the changelog for v0.16.0: https://github.com/thoughtbot/administrate/releases/tag/v0.16.0 As for other breaking changes, we try to keep things back-compatible or give deprecation warnings, but there is not guarantee that something won't slip through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug breakages in functionality that is implemented
Projects
None yet
Development

No branches or pull requests

3 participants