我可以在Sinatra项目中使用strong_params吗?是否有相同的Sinatra选项?
答案 0 :(得分:3)
你有没有试过Mattt Thompson的Sinatra Param?它的实现略有不同,但结果类似于Rails强大的params。
根据文档示例:
# 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