AlexWayfer/flame

Query params from root Hash-argument for `path_to`

AlexWayfer opened this issue · 6 comments

Now:

# request.path => '/en/2?foo=bar'

# params => { id: 2, locale: 'en', foo: 'bar' }

path_to :show, params.merge(params: request.params.merge(new_arg: 'value'))
# => '/en/2?foo=bar&new_arg=value

Expected:

path_to :action, params.merge(new_arg: 'value')

@AlexWayfer pardon my ignorance of the library. I'm still learning.

path_to :show, params.merge(params: ...

wouldn't this give params.params... within :show action?

AlexWayfer pardon my ignorance of the library. I'm still learning.

No problem.

wouldn't this give params.params... within :show action?

I didn't understand the question.

params is a regular Hash, it doesn't have #params method.

@AlexWayfer

params.merge(params: request.params.merge(new_arg: 'value'))

Perhaps been staring at Javascript too long but shouldn't be

params.merge(request.params.merge(new_arg: 'value'))

The way you have it would create a root params key containing the request params when I believe you want to merge the 3 tuples into one giant params. Either initial params is named wrong or nested params are being merged a level too deep. Correct me where i'm wrong.

/cc @brandondees

capture d ecran 2018-03-15 a 01 46 15

@snuggs Yes, you're right. It's what about this issue (see "expected"; params and request.params are almost the same).

Problem:

  1. path_to receives parameters for actions (id for def show(id) action) at root Hash, and parameters for query string (/?foo=bar) as Hash at params key (params: { foo: :bar }).
  2. params contains request.params (you can see info about this in the Rack::Request documentation) + action's parameters (id for def show(id).

So, there is detailed example:

def edit(id)
  p params # => { foo: 'bar', id: 2 }
  path_to :edit, id: 2, params: { foo: 'bar' } # => '/edit/2?foo=bar'
end

That should be changed to be more intuitive.

I see now @AlexWayfer