Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8200417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:26:35+00:00 2026-06-07T06:26:35+00:00

I have a rails app with a Backbone.js front-end. In my Backbone model/collection definition,

  • 0

I have a rails app with a Backbone.js front-end. In my Backbone model/collection definition, I have the following for a model (in project.js.coffee.erb)

#############################
##  MODEL
#############################
class window.Project extends Backbone.Model

  urlRoot: '/projects'

#############################
##  COLLECTION
#############################
class window.Projects extends Backbone.Collection

  model: Project

  url: '/projects'


# initialize new collection
window.projects = new Projects
projects.reset(<%= Project.all.to_json %>)

The last line is where ERB loads in all the projects in JSON.

When I load my application, this bootstraping results in a collection that contains old data. I know it’s old because I’ve gone as far as to:

  • delete my development database (sqlite3)
  • alter my database.yml to rename my development database name
  • re-run rake db:migrate to create a brand new .sqlite3 database file

I can run sqlite3 and see that the projects table contains no rows, and yet, even after restarting the server, project.js is compiled to contain a collection full of now non-existent data.

Rails correctly boots into development mode when I run rails s:

=> Booting WEBrick
=> Rails 3.2.5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-07-02 21:24:08] INFO  WEBrick 1.3.1
[2012-07-02 21:24:08] INFO  ruby 1.9.3 (2012-04-20) [x86_64-darwin11.4.0]
[2012-07-02 21:24:08] INFO  WEBrick::HTTPServer#start: pid=11607 port=3000

If I create new projects, they even save to the database. They also get added to the Backbone collection just fine. But, again, if I reload the page or even restart the server, the collection is again populated with the old data.

Can someone help me figure out what I’m doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:26:37+00:00Added an answer on June 7, 2026 at 6:26 am

    Ok, turns out I figured out what’s going on.

    Assets in rails are cached so long as the file itself doesn’t change. So once project.js.coffee.erb was compiled into project.js, the data being bootstrapped into the collection would remain static until I made a change to project.js.coffee.erb, at which point rails would re-compile the file, only then re-fetching the data from the database.

    I realized that if I want new data to be bootstrapped into the collection on each page load, I’d need to add the projects.reset() javascript as an inline script in the main app/views/layouts/application.html.haml. Adding this code to the end of my body tag did the trick.

    :javascript
      projects.reset(#{Project.all.to_json})
      groups.reset(#{Group.all.to_json})
      users.reset(#{User.all.to_json})
    

    Now, each time the page is reloaded, the current data is loaded into the appropriate collections.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple rails 3.2 app with a Backbone.js front-end. I have the
I have notifications in my Rails & Backbone.js app // MODEL NotificationModel = App.BB.Model.extend({
I'm using codebrew\backbone-rails in a nested model example (say I have a collection of
I have a Rails 3.2.3 app with Backbone.js and I'm using pushState on my
I have a Rails app with the usual application_controller, and a controller (and model)
I have a rails app where i have a Contact model and with an
I have a rails-backbone project that generates jst.ejs templates. I'd like to include some
I have a Rails 3.1 app that uses the codebrew/backbone-rails . In a .jst.ejs
I have a single page app (Rails + Backbone.js + Postgres on Heroku), and
I have a simple List-style Backbone app that I'm making with a Rails backend.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.