2017-03-03 115 views
0

對於我的一種方法,以下方法無效。我幾乎複製所有直接從官方文檔的:紅寶石/葡萄在一定條件下所需的參數

params do 
requires :authenticationType, type: Array[String], values: ['LOCAL', 'AD'] 
given authenticationType: ->(val) { val == 'LOCAL' } do 
    requires :admin, type: String, allow_blank: false, regexp: /^[\w\.\@-]{1,64}$/ 
    requires :password, type: String, allow_blank: false, regexp: /^[\w\.\@-]{1,64}$/ 
end 
end 

這是給在「給定」行一個錯誤。任何人都知道什麼是錯的。我的目標:僅當「authenticationType」 ==「本地」應該向用戶提供「管理員」和「密碼」

錯誤:

[ 2017-03-03 00:39:18.4848 14970/7f5d0603f700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /vagrant/masterapi: An error occurred while starting up the preloader. Error ID: 0bd79149 Error details saved to: /tmp/passenger-error-3OYsdJ.html Message from application: Grape::Exceptions::UnknownParameter (Grape::Exceptions::UnknownParameter)
/usr/local/lib/ruby/gems/2.3.0/gems/grape-0.16.2/lib/grape/dsl/parameters.rb:170:in block in given'
/usr/local/lib/ruby/gems/2.3.0/gems/grape-0.16.2/lib/grape/dsl/parameters.rb:169:in
each'
/usr/local/lib/ruby/gems/2.3.0/gems/grape-0.16.2/lib/grape/dsl/parameters.rb:169:in given' /vagrant/masterapi/controllers/papi_controller.rb:93:in block in '

+0

你應該顯示錯誤。 –

回答

0

「給定」接受PROC只因爲葡萄版本0.17,實施在合併請求(MR)1443。所以你應該更新,或者如果這不可行,請嘗試將此MR重新移植到0.16.2。

Here's您的版本的自述文件。

另外,在你的例子中,authenticationType參數類型爲Array[String],所以(至少在葡萄0.17中),proc將收到Hashie::Array

這意味着:

->(val) { val == 'LOCAL' }

應該

->(val) { val.first == 'LOCAL' }