在Rails 4.2.4中,ActionController::Parameters.new(pos: 'xyz', foo: 'bar').to_query
返回"foo=bar&pos=xyz"
。
升级到Rails 5.0后,我明白了:
ArgumentError: wrong number of arguments (given 0, expected 1)
from /Users/Lars/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.rc2/lib/active_support/core_ext/object/to_query.rb:11:in `to_query'
from (irb):7
from /Users/Lars/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.rc2/lib/rails/commands/console.rb:65:in `start'
from /Users/Lars/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.rc2/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/Lars/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.rc2/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/Lars/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.rc2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/Lars/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/railties-5.0.0.rc2/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
但to_query
的文档明确指出to_query的参数是(仍然)可选:http://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-to_query
有什么想法吗?