2

I am trying to use Ember.js in my Rails project. I created scaffold of a ToDo application. Added the 'emberjs-rails' gem to my Gemfile right near the top. Added ember to my application.js right after JQuery:

   //= require jquery
   //= require jquery_ujs
   //= require ember
   //= require_tree .

I then added the following code to a view, expecting to see the text field when accessing it:

    <script type="text/x-handlebars">
     {{view Em.TextField id="new-todo" placeholder="the text"}}
    </script>

When I access this view I get the following error in the console:

   Error: assertion failed: Ember requires jQuery 1.6 or 1.7
   [Break On This Error]    

   if (!test) throw new Error("assertion failed: "+desc);

I first assumed this error is caused because rails is integrating an older version of JQuery in my application. But when I checked the script section in the debugger I can see JQuery 1.8 is loaded:

   jQuery JavaScript Library v1.8.1

Looking at page source I can see that both Ember and JQuery are added. The little handlebar script is also present. However, it seems that it does not get interpreted due to the above error.

What am I missing here, how can I ensure that Ember dependency on JQuery is satisfied in my rails application?

Edit (Solution): As stef pointed out below, I needed to drop back to JQuery version 1.7. Current version of ember does not support JQuery 1.8. I am using jquery-rails gem to manage my jquery. I learnt from another SO post on how to specify the version of jquery that I want to load (by specifying the corresponding version of jquery-rails. To solve this issue I use version 1.0.19 or higher minor releases of jquery-rails. Using the funny ~> symbol does not load the next major release which is 2 in this case.

    gem 'jquery-rails', '~>1.0.19'

Next I run bundle under application directory to install desired version of jquery-rails. You can do a gem list to verify. After restarting rails and refreshing the browser, I get my text box, so it appears now that Ember.js dependency is satisfied.

Community
  • 1
  • 1
Aras
  • 5,878
  • 9
  • 49
  • 76

1 Answers1

2

Ensure you are using the correct version of jQuery (Updated based on comments).

Ember recently stopped bundling many of its dependencies, so you have to include them manually before ember.js. Check your application template and ensure jQuery is included before Ember (if it's separate files), and also in your application.js manifest file.

stef
  • 14,172
  • 2
  • 48
  • 70
  • Ember is already after JQuery in the application.js file (see my edit). In the page source JQuery is included before ember. Both libraries are actually loaded in the page -- but I get the error above. How can I specify JQuery 1.7 to be loaded instead of latest? – Aras Sep 08 '12 at 20:39
  • 1
    I figured out how to use previous version of JQuery. Add gem 'jquery-rails', '~>1.0.19' to Gemfile to specify previous version. – Aras Sep 08 '12 at 21:30
  • I accepted your answer since you said to roll back to jQuery 1.7. Please consider editing your post and emphasizing that the actual solution. – Aras Sep 08 '12 at 21:47