[英]Adding Parameters to Backbone.js collection causing ArgumentError (wrong number of arguments … for filter method
我可以使用collection.fetch方法與我的骨干服務器很好地同步
UserActionCollection extends Backbone.Collection
url: "/api/user_actions"
model: UserActionModel
userActions = new UserActionCollection()
userActions.fetch()
這使我的收藏充滿了預期的模型
但是,當我嘗試添加數據過濾器時
userActions.fetch({data: $.param({collabList: true })})
我的Ruby on 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()時,params值為:
[1] pry(#<UserActionsController>)> params
=> {"action"=>"index", "controller"=>"user_actions"}
當我繼續時,一切都會正常。
當我調用userActions.fetch({data:$ .param({collabList:true})})時,您可以看到以下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"}
當我鍵入next並處理第14行時,它將引發異常
#<ArgumentError: wrong number of arguments (0 for 1..2)>
我是否錯誤地傳遞了參數?
是否由於某些原因未傳遞params變量?
謝謝您的幫助/建議!
重新啟動我的Rails服務器修復了它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.