leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
537 stars 215 forks source link

Params conversion error on Rails 4 #140

Closed creasty closed 10 years ago

creasty commented 10 years ago

Situation

  1. Visit /foo
  2. Search id attributes for "1" it shows /foo?grid%5Bf%5D%5Bid%5D%5Beq%5D=1.
  3. Search again it attempts to show /foo?grid=&grid%5Bf%5D%5Bid%5D%5Beq%5D=2.
    and causes the framework to raise an error:
    expected Hash (got String) for param 'grid'

    Cause

https://github.com/leikind/wice_grid/blob/rails4/lib/wice/grid_renderer.rb#L467

base_link_with_pp_info = controller.url_for(new_params).gsub(/\?+$/,'')

I'm not sure this is a bug of Rails 4, but certainly url_for's behavior has been changed.

For instance, on Rails 3.2:

root_path(grid: {})
#=> /?

Whereas on 4:

root_path(grid: {})
#=> /?grid=

So if you simply append &grid[key]=value to ?grid=, and make ?grid=&grid[key]=value, Rails can't parse it into Hash.

creasty commented 10 years ago

Thank you for merging. Now I close this issue.