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

Add "check_parameters" option to "current_page?" #27549

Merged
merged 1 commit into from Jan 5, 2017

Conversation

Projects
None yet
5 participants
@mpugach
Contributor

mpugach commented Jan 3, 2017

Example:

For http://www.example.com/shop/checkout?order=desc&page=1

current_page?('http://www.example.com/shop/checkout')
# => true

current_page?(
  'http://www.example.com/shop/checkout',
  check_parameters: true
)
# => false

This is needed when http://www.example.com/shop/checkout navigation is also present on the page. Without this option both paths are considered current.

@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Jan 3, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

rails-bot commented Jan 3, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@mpugach mpugach changed the title from Add strict_params option to current_page? to Add "strict_params" option to "current_page?" Jan 3, 2017

@maclover7 maclover7 added the actionview label Jan 3, 2017

Show outdated Hide outdated actionview/lib/action_view/helpers/url_helper.rb
@@ -539,12 +542,14 @@ def current_page?(options)
return false unless request.get? || request.head?
strict_params ||= !options.is_a?(String) && options.try(:delete, :strict_params)

This comment has been minimized.

@rafaelfranca

rafaelfranca Jan 4, 2017

Member

Why this line is needed? Should not the keyword argument take care of this?

@rafaelfranca

rafaelfranca Jan 4, 2017

Member

Why this line is needed? Should not the keyword argument take care of this?

This comment has been minimized.

@mpugach

mpugach Jan 4, 2017

Contributor

not always

def ololo(options, some_keyword: false)
  puts options.inspect
  puts some_keyword.inspect
end

ololo(action: :index, controller: :some, some_keyword: :tralala)
# {:action=>:index, :controller=>:some, :some_keyword=>:tralala}
# false
@mpugach

mpugach Jan 4, 2017

Contributor

not always

def ololo(options, some_keyword: false)
  puts options.inspect
  puts some_keyword.inspect
end

ololo(action: :index, controller: :some, some_keyword: :tralala)
# {:action=>:index, :controller=>:some, :some_keyword=>:tralala}
# false

@maclover7 maclover7 added the needs work label Jan 4, 2017

Show outdated Hide outdated actionview/lib/action_view/helpers/url_helper.rb
@@ -530,7 +533,7 @@ def mail_to(email_address, name = nil, html_options = {}, &block)
#
# We can also pass in the symbol arguments instead of strings.
#
def current_page?(options)
def current_page?(options, strict_params: false)

This comment has been minimized.

@rafaelfranca

rafaelfranca Jan 4, 2017

Member

Maybe check_paramters is a better name?

@rafaelfranca

rafaelfranca Jan 4, 2017

Member

Maybe check_paramters is a better name?

@mpugach mpugach changed the title from Add "strict_params" option to "current_page?" to Add "check_parameters" option to "current_page?" Jan 4, 2017

@mpugach

This comment has been minimized.

Show comment
Hide comment
@mpugach

mpugach Jan 4, 2017

Contributor

@rafaelfranca, updated

Contributor

mpugach commented Jan 4, 2017

@rafaelfranca, updated

@rafaelfranca rafaelfranca merged commit 333283e into rails:master Jan 5, 2017

2 checks passed

codeclimate no new or fixed issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@maclover7 maclover7 removed the needs work label Jan 5, 2017

Edouard-chin added a commit to Edouard-chin/rails that referenced this pull request Apr 24, 2017

Fix `current_page?` regression:
- `check_parameters` kwargs was added to the `current_page?` method, the implementation was assuming only hashes responds to `delete`. This was causing issues when `current_page?` was called with a Active Model object
- ref rails#27549
- Fixes #28846

Edouard-chin added a commit to Edouard-chin/rails that referenced this pull request Apr 26, 2017

Fix `current_page?` regression:
- `check_parameters` kwargs was added to the `current_page?` method, the implementation was assuming only hashes responds to `delete`. This was causing issues when `current_page?` was called with a Active Model object
- ref rails#27549
- Fixes #28846
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment