Thursday, 22 August 2013

Adding Parameters to Backbone.js collection causing ArgumentError (wrong number of arguments ... for filter method

Adding Parameters to Backbone.js collection causing ArgumentError (wrong
number of arguments ... for filter method

I can sync with my backbone server perfectly well using the
collection.fetch method
UserActionCollection extends Backbone.Collection
url: "/api/user_actions"
model: UserActionModel
userActions = new UserActionCollection()
userActions.fetch()
This fills up my collection with the expected models
However when I attempt to add a data filter
userActions.fetch({data: $.param({collabList: true })})
My ruby on rails server pops up this error:
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'
My Controller for the index fetch is:
def index
respond_with UserAction.filter_by_params(params)
end
My Model Definition with the definition for 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
I stuck a binding.pry at the controllers index method and when I call
userActions.fetch() the params value is:
[1] pry(#<UserActionsController>)> params
=> {"action"=>"index", "controller"=>"user_actions"}
And everything works when I continue.
When I call the userActions.fetch({data: $.param({collabList: true })})
you can see the params value below:
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"}
When I type next and process line 14, It throws an exception
#<ArgumentError: wrong number of arguments (0 for 1..2)>
Am I passing in parameters incorrectly?
Is there some reason the params variable isn't being passed in?
Thanks for any help/insight you can give me!

No comments:

Post a Comment