2014-11-23 65 views

回答

3

您是否嘗試過Mattt Thompson的Sinatra Param?它的實現稍有不同,但結果類似於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