javascript - Backbone Collection url with dynamic parameters -



javascript - Backbone Collection url with dynamic parameters -

i'm writing rails app backbone.js.

in rails, have route in config/routes.rb takes argument this: /api/u/foo. gets posts argument, in case foo. output of posts foo. foo user, has many posts.

in backbone, need set url attribute on collection take arguments route, this: /u/foo. want go /api/u/foo.json. how this? tried taking user argument on backbone route, could't collection.

the relevant part of routes.rb file:

scope 'api' "/u/:user", :action => "index", :controller => "posts" end

assuming foo parameter, makes sense backbone apply url fetch single user, not collection.

i believe routes fine /api/u should homecoming collection , /api/u/123 single user. want send parameters /api/u?foo=bar filter collection.

just send these in .fetch() phone call in backbone working. apply necessary changes in controller filter according various parameters possible.

update

knowing want posts per user, question has nested routes. has been asked here: backbone , rails nested routes

the documentation on backbone.js here: http://documentcloud.github.com/backbone/#faq-nested

to remain bit more restful, define routes so:

scope '/api' resources :users, only: [], path: 'u' resources :posts, only: :index end end

which results in:

api_user_posts /api/u/:user_id/posts(.:format) api/posts#index

javascript ruby-on-rails backbone.js

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -