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.