I'm using Rails 3.1 and Backbone.js to create an application. Working with a collection of models, pulled from a database (via Rails controller) I am getting every attribute from the database to javascript. But with the same methods and code to do the same thing with another model and I'm not getting the database 'id' for the second model.
Here's the code that is working:
window.Post = Backbone.Model.extend
urlRoot: '/posts'
defaults:
author_id: 2
window.Posts = Backbone.Collection.extend
model: Post
url: '/posts'
Controller:
respond_to :html, :json, :js
def index
@posts = current_user.posts
respond_with(@posts.to_json(:include => {:account => {:only => :institution}}))
end
With this above I get a model with an attribute of id that is pulled from the database, but below does not contain the id attribute for the User model
And this is not:
window.User = Backbone.Model.extend
urlRoot: '/members'
window.Users = Backbone.Collection.extend
model: User
url: '/members'
Controller:
respond_to :html, :json, :js
def index
@users = @account.users
respond_with(@users)
end