Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails/Ruby: Is there a backbone gem in that doesn't generate coffeescript files?

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
like image 608
Leahcim Avatar asked Apr 09 '12 18:04

Leahcim


2 Answers

In case someone finds this question through Google.

# Generate JavaScript
rails generate backbone:install --javascript

Source: backbone-on-rails README under Tricks

like image 71
joelam Avatar answered Nov 19 '22 07:11

joelam


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:

  • Add 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.

like image 2
Graham Swan Avatar answered Nov 19 '22 08:11

Graham Swan