Sinatra的强参数?

时间:2014-11-23 16:38:12

标签: ruby-on-rails-4 sinatra strong-parameters

我可以在Sinatra项目中使用strong_params吗?是否有相同的Sinatra选项?

1 个答案:

答案 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