grape
grape copied to clipboard
param as is not work
params do
optional :page_size, as: :per_page, type: Integer
end
params #=> {page_size: 10} not have per_page
declared(params) #=> {per_page: 10}
i upgrade from 1.31 to 1.6.0
@brynary @tmornini @ctennis @olleolleolle @bernd How should I write? thanks
This seems to work as expected, what output did you expect?
This seems to work as expected, what output did you expect?
@dblock Thank you for your reply
params do
optional :page_size, as: :per_page, type: Integer
end
params #=> {per_page: 10}
declared(params) #=> {per_page: 10}
@dblock https://github.com/ruby-grape/grape/blob/v1.3.1/lib/grape/validations/params_scope.rb#L132
@ly123525 it is recommended to use declared(params) to avoid mass assignment. I wouldn't fix anything in Grape.
@ly123525 it is recommended to use
declared(params)to avoid mass assignment. I wouldn't fix anything in Grape.
@dnesteryuk while your suggestion is good, the current behavior still looks like a bug because we have a clear description in README for how it should work.
The value passed to as will be the key when calling
paramsordeclared(params).
And it'd worked it such way previously but not now. Looks like a breaking change.
So did we introduce a regression, and in which version? Or should we change nothing and update documentation?
@dnesteryuk does it change anything in your comment?
ok, I figured it out when this behavior was changed, actually, it is described in the upgrading doc, so it isn't a bug, it is how Grape works after 1.6.0 and the motivation of the change makes sense.
@dm1try probably, we need to update the doc :wink:
@ly123525 or someone else here, care to update? thanks