0
我可以用我的骨幹服務器非常清楚使用方法collection.fetch添加參數,以收集Backbone.js的導致引發ArgumentError(錯誤的參數數目......對於過濾方法
UserActionCollection extends Backbone.Collection
url: "/api/user_actions"
model: UserActionModel
userActions = new UserActionCollection()
userActions.fetch()
這填補了我的收藏同步與預期的模型
然而,當我嘗試添加一個數據過濾器
userActions.fetch({data: $.param({collabList: true })})
我的Rails服務器上的紅寶石彈出這個錯誤:
Processing by UserActionsController#index as JSON
Parameters: {"collabList"=>"true"}
Completed 500 Internal Server Error in 9214ms
ArgumentError (wrong number of arguments (0 for 1..2)):
app/models/user_action.rb:16:in `filter_by_params'
app/controllers/user_actions_controller.rb:14:in `index'
我的控制器,用於指標取爲:
def index
respond_with UserAction.filter_by_params(params)
end
我與定義filter_by_params
class UserAction < ActiveRecord::Base
attr_accessible :action, :context, :itemID, :itemType, :userId, :userName, :userEmail
def self.filter_by_params(params)
scoped = self.scoped
if (params[:collabList])
scoped = scoped.uniq.pluck(:userName)
end
return scoped
end
end
我在控制器索引方法貼附在binding.pry並且當模型定義我打電話給userActions.fetch(),參數值是:
[1] pry(#<UserActionsController>)> params
=> {"action"=>"index", "controller"=>"user_actions"}
當我繼續時,一切正常。
當我打電話userActions.fetch({數據:$ .PARAM({collabList:真})})你可以看到下面的PARAMS值:
12: def index
=> 13: binding.pry
14: respond_with UserAction.filter_by_params(params)
15: end
[1] pry(#<UserActionsController>)> params
=> {"collabList"=>"true", "action"=>"index", "controller"=>"user_actions"}
當我鍵入下一個和工藝生產線14 ,它會拋出一個異常
#<ArgumentError: wrong number of arguments (0 for 1..2)>
我的參數傳遞不正確嗎?
是否有某些原因PARAMS變量沒有被傳入?
感謝您的任何幫助/見解,您可以給我!