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')
Be careful with Flame::Flash#extract_flashes
.
@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.
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
@snuggs Yes, you're right. It's what about this issue (see "expected"; params
and request.params
are almost the same).
Problem:
path_to
receives parameters for actions (id
fordef show(id)
action) at root Hash, and parameters for query string (/?foo=bar
) as Hash atparams
key (params: { foo: :bar }
).params
containsrequest.params
(you can see info about this in theRack::Request
documentation) + action's parameters (id
fordef 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