使用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
我在controllers索引方法上粘贴了binding.price,当我调用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服务器修复了它。