Not sure if this question belongs on stackoverflow....
I'm trying to follow along with Ryan Bates Railscast on Backbone.js. He uses a gem 'backbone-on-rails' that generates coffeescript files. Even if I copy the code exactly as he has it, I'm getting all sorts of weird errors (INDENT errors) and the code's just not working even though, as I said, I'm being very careful about the spaces.
On several occasions, I was able to fix a problem by retyping the code exactly as I had it!
My productivity, already slow, has now ground to a halt using coffeescript, so I'm wondering if there's another backbone.js gem that doesn't use coffee script
For example, here's another error message I've got even though there's no indent and I didn't copy the code from the internet.
Error: Parse error on line 2: Unexpected 'INDENT'
Another example, the handleError function is supposed to be triggered on an error (and alert message) trying to create an entry. It works on the RailsCast but not in my application.
createEntry: (event) ->
event.preventDefault()
attributes = name: $('#new_entry_name').val()
@collection.create attributes,
success: -> $('#new_entry')[0].reset()
error: @handleError
handleError: (entry, response) ->
if response.status == 422
errors = $.parseJSON(response.responseText).errors
for attribute, messages of errors
alert "#{attribute} #{message}" for message in messages
In case someone finds this question through Google.
# Generate JavaScript
rails generate backbone:install --javascript
Source: backbone-on-rails README under Tricks
The most popular Backbone.js gem for Rails is this: https://github.com/codebrew/backbone-rails. It does not provide functionality for generating Backbone apps in native JavaScript.
You can use the runner-up gem at https://github.com/meleyal/backbone-on-rails if you'd like to generate a Backbone app in JavaScript. Simply run the following commands:
gem 'backbone-on-rails'
to your Gemfile
bundle install
rails generate backbone:install -j
rails generate backbone:scaffold user -j
I highly encourage you to learn CoffeeScript, though. Once you nail the syntax down, you'll be able to develop client-side apps at an increasingly rapid rate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With