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

url_for skip params which given as defaults #31297

Closed
distroid opened this issue Nov 30, 2017 · 6 comments
Closed

url_for skip params which given as defaults #31297

distroid opened this issue Nov 30, 2017 · 6 comments
Labels

Comments

@distroid
Copy link

Steps to reproduce

I use STI model and one controller with type for initialize different resources:

resources :partners, controller: :companies, defaults: { type: 'Partner' }
resources :providers, controller: :companies, defaults: { type: 'Provider' }

Routes works as expected for CRUD

For pagination i use kaminari. I think problem in helper method url_for he ignored overrided params from defaults and always return url with first initialized route (currently it's partners).

For example:

paginate @records, params: { type: 'Provider' }

It's will be ignored and type skipped.

Expected behavior

For /partners in pagination should be /partners?page=<number>
For /providers in pagination should be /providers?page=<number>

Actual behavior

For /partners in pagination i get /partners?page=<number>
For /providers i also get /partners?page=<number>

System configuration

Rails version:
Rails 5.1.4

Ruby version:
ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-darwin16]

Related #27132

@y-yagi
Copy link
Member

y-yagi commented Dec 1, 2017

Can you please provide a sample application that reproduces the error?

@distroid
Copy link
Author

distroid commented Dec 4, 2017

@y-yagi sure, I will do this and add here a link

@pixeltrix
Copy link
Contributor

@distroid why not use a CompaniesController parent class and subclasses for PartnersController and ProvidersController ? You can then drop the :type param from url_for and it will use the correct controller.

@distroid
Copy link
Author

distroid commented Dec 5, 2017

@pixeltrix yes, you right, it's will be work. But i think :type should work for my case. Because controllers with :type works as expected and bug only with pagination or generate url by url_for.
url_for always skipped defaults params.

@pixeltrix
Copy link
Contributor

@distroid as I explained in #27132 this will be a change of behaviour and will result in people's apps generating different routes - something we can consider for Rails 6 maybe.

@rails-bot rails-bot bot added the stale label Mar 5, 2018
@rails-bot
Copy link

rails-bot bot commented Mar 5, 2018

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 5-1-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot closed this as completed Mar 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants