Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload