ruby on rails - Should Backbone Model represent a view or a server-side resource? -


assume situation i've rails ar models below

class user   has_one :profile end  class profile   belongs_to user   has_one :address end  class address   belongs_to :profile end 

and have user profile view constructed @ client-side. now, how should backbone model like? should replicate way in rails/server-side domain model? have clear reason way has way, or subjective?

your experience sharing appreciated!

usually backbone models , collections should follow rest api ( or other client-side <-> server-side communication ).

  1. for example if these ruby models passed frontend :

    get /api/user/:id 

    and got response is

    [{ profile: { address: "21st str." } },{ profile: { address: "17th str." } }] 

    you need 1 model

    user = backbone.model users = backbone.collection.extend({    model: user,    url: "/api/user" }); 
  2. but if more complicated in api , have more urls in api choose structure best fits interaction client on frontend. example if website doesn't need user api @ , pass data frontend urls:

    get /api/profile 

    you can have 1 model

    profilemodel = backbone.model.extend({     url: "/api/profile" }) 

    and can set address like

    profile = new profilemodel(); profile.set('address', '21st str.'); 

bottom line

backbone should follow url structure of rest api. if enjoy full benefits of using it's rest ajax calls ( get, post, delete, put ) autoconfigured.

usually don't is make backbone app structure follow database schema. may cause headache, because need create way backend ( ruby app ) able provide same database access orm using.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -