amatsuda/kaminari — pull request #267 by leikind (2012-07-29 18:11:58+00:00)
Title: Support for complex :param_name such as 'scope[page]'

Perhaps, in 999 cases out of 1000 the page parameter is a simple HTTP parameter such as `page`, but sometimes a more complext name is required, like `some_scope[page]`. (Example: many tables on one page, each having a number of associated HTTP parameter scoped into groups like `grid1[param1]`, `grid1[param2]`, etc. http://wicegrid.herokuapp.com/many_grids_on_page).

Kaminari fails to generate page linked correctly because of the following code:

```ruby
def page_url_for(page)
@template.url_for @params.merge(@param_name => (page <= 1 ? nil : page))
end
```
If `:page_name` is `scope[page]`, and `@params` of the current page already has this parameter, this code merges a `@params` hash like `{'scope' => {'page' => '42'} }` with `{'scope[page]' => 43}`. This is wrong.

We need to
1) transform `{'scope[page]' => 43}` into `{'scope' => {'page' => '43'} }`. It can be done with `Rack::Utils.parse_nested_query`
2) recursively merge the two hashes so that `{'scope' => {'page' => '42', 'some_other_key' => 'some_other_value'} }`
merged with `{'scope' => {'page' => '43', 'yet_another_other_key' => 'yet_another_other_value'} }` results in
`{'scope' => {'page' => '43', 'yet_another_other_key' => 'yet_another_other_value', 'some_other_key' => 'some_other_value'} }`

I placed the recursive merging routine right into `Kaminari::Helpers` because polluting the `Hash` class doesn't seem like a good idea, but still, `Kaminari::Helpers` doesn't seem a good place for this code either. I am just making a suggestion here.

Testing the plugin with you test suite revealed that with Sinatra `@template.url_for` expects keys to be symbols, and doesn't work correctly if they are strings, so I added a recursive `symbolize_keys`