gpt4 book ai didi

ruby-on-rails - 是否可以过滤对 Grape API 的请求的参数?

转载 作者:行者123 更新时间:2023-12-04 03:36:55 25 4
gpt4 key购买 nike

如果我在 Grape API 请求上设置参数验证,是否可以仅获取已验证参数的哈希?

desc "My Grape API request handler"
params do
requires :name
optional :description
end
post do
puts params.inspect # has all the params passed to request,
# even params not defined in validation block
end

是否有另一种方法可以将 params 限制为参数验证 block 中列出的那些?有点像 Rails strong_parameters 的工作原理。

最佳答案

可能会晚,但对于任何路过的人,您可以使用 declared_pa​​ramshttps://github.com/ruby-grape/grape#declared

关于ruby-on-rails - 是否可以过滤对 Grape API 的请求的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21739404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com