>我可以在Sinatra项目中使用strong_params吗?有没有同样的辛纳屈选项?
你试过马特·汤普森的《辛纳屈·帕拉姆》吗?它的实现略有不同,但结果类似于强参数对 Rails 的作用。
根据文档示例:
# GET /search?q=example
# GET /search?q=example&categories=news
# GET /search?q=example&sort=created_at&order=ASC
get '/search' do
param :q, String, required: true
param :categories, Array
param :sort, String, default: "title"
param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC"
param :price, String, format: "[<=>]s*$d+"
{...}.to_json
end