Turbolinks causing a "jquery-ujs has already been loaded!" error

Viewed 20004

I have a newish Rails 4 app which contains no custom Javascript - the folders app/assets/javascripts, lib/assets/javascripts and vendor/assets/javascripts are all empty (apart from app/assets/javascripts/application.js).

When I click around the app I keep getting the error jquery-ujs has already been loaded! in the JS console. It happens every time I hit the "back" button, and sometimes when I click a normal link (although I can't make it happen consistently.)

application.js:

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require turbolinks
//= require_tree .

When I remove turbolinks from application.js, I stop getting the error... so turbolinks appears to be the culprit.

Is this a bug with turbolinks, or am I doing something wrong?

Here's my Gemfile:

source 'https://rubygems.org'

ruby '2.0.0'

gem 'rails', '4.0.0'

gem 'active_model_serializers'
gem 'aws-sdk'
gem 'bootstrap-sass-rails'
gem 'coffee-script-source', '1.5.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'devise'
gem 'factory_girl_rails', '4.1.0'
gem 'figaro'
gem 'font-awesome-sass-rails'
gem 'jbuilder', '~> 1.2'
gem 'jquery-rails'
gem 'paperclip'
gem 'paperclip-meta', github: 'y8/paperclip-meta'
gem 'pg'
gem 'sass-rails', '~> 4.0.0'
gem 'turbolinks'
gem 'uglifier', '>= 1.3.0'

group :production do
  gem 'rails_12factor'
end

group :doc do
  gem 'sdoc', require: false
end

group :test do
  gem 'capybara', '2.1.0'
end

group :development, :test do
  gem 'childprocess', '0.3.9'
  gem 'debugger'
  gem 'faker', '~> 1.2.0'
  gem 'json_spec'
  gem 'rspec-rails'
  gem 'rspec-mocks'
end

group :development do
  gem 'annotate'
  gem 'hirb'
  gem 'wirb'
end

Changing around the order of the requires in application.js doesn't seem to help either.

4 Answers

The problem that I had It was that I copied the <%= render 'layouts/head'%> twice!, in the head and in the body. check the laouts/application.html.erb file

Related