1

I got a problem with jQuery.ui and Rails. I try to solve this error since 6 hours but I can't find a solution. This is especially annoying that it seems simple. Sure I am missing something.

When I add <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> to the head of my application.html.erb, it works but only if the input is placed inside application.html.erb :

<%= javascript_include_tag "application", "data-turbolinks-track" => true %>

<form method="post">
   Date:<input type="text" id="datepicker" name="datepicker" />
</form>

If the form is placed in ANY other view, the date picker function will not works.

in application.js:

//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require jquery.turbolinks 
//= require turbolinks
//= require welcome
//= require subscriptions
//= require to_do_lists
//= require_tree .

$(function() {
    $( "#datepicker" ).datepicker();
});

in gemfile :

gem 'jquery-ui-rails', '~> 5.0', '>= 5.0.5'

in application.css :

/*
 *= require_self
 *= require jquery.ui.all
*/

I face two problems :

  1. First, jQuery-ui gem won't works
  2. Second, even if I call the script in the head of my app, it works only with a form in application.html.erb

EDIT with my Gemfile:

source 'https://rubygems.org'
source 'https://code.stripe.com' do
    gem 'stripe'
end

ruby "2.2.4"

gem 'rails', '4.2.3'

gem 'pg', '~> 0.15'

gem 'sass-rails', '~> 5.0'

gem "gibbon"

gem 'uglifier', '>= 1.3.0'

gem 'coffee-rails', '~> 4.1.0'

gem 'aws-sdk', '< 2.0'

gem 'jbuilder', '~> 2.0'

gem 'friendly_id', '~> 5.0.0'

gem 'sdoc', '~> 0.4.0', group: :doc

gem 'rails_12factor'

gem 'meta-tags'

gem 'devise'

gem 'factory_girl_rails'

gem 'rails_serve_static_assets'

gem 'capybara'

gem 'kaminari'

gem 'figaro'

gem 'guard-rspec'

gem 'paperclip'

# jquery gems for rails
gem "jquery-rails"

gem 'jquery-ui-rails'

gem 'puma'

gem 'therubyracer'

gem 'paper_trail'

group :development, :test do

  gem 'byebug'
  gem 'stripe-ruby-mock'
  gem 'database_cleaner'
  gem 'rspec-rails'
  gem 'rails_best_practices'
  gem 'brakeman'
  gem 'quiet_assets'

end

group :development do

  gem 'web-console', '~> 2.0'

  gem 'spring'
end

Any idea ?

9
  • document.ready ? Commented May 9, 2016 at 13:57
  • If you are using chrome, please post the developer console log - this could help in identifying the problem Commented May 9, 2016 at 14:10
  • @TimothéGauguet : Just replace //= require jquery.ui.all with //= require jquery-ui in application.js and application.css Commented May 9, 2016 at 14:11
  • @EmilianoDellaCasa, I did but there are no errors Commented May 9, 2016 at 14:13
  • @Akshay, sorry, my code is actually this one (//= require jquery-ui), I updated the gem since I posted my question but it didn't solved the problem Commented May 9, 2016 at 14:15

3 Answers 3

1

I think you are not requiring plugin properly in application.js and application.css. Please try this and let me know if you still facing problem.

In your Gemfile, add:

gem 'jquery-ui-rails'

Require Everything

To require all jQuery UI modules, add the following to your application.js:

//= require jquery-ui

Also add the jQuery UI CSS to your application.css:

/* *= require jquery-ui */

Sign up to request clarification or add additional context in comments.

2 Comments

It was properly written, I have exactly this code in my files
@TimothéGauguet : Just replace //= require jquery.ui.all with //= require jquery-ui in application.js and application.css
0

Just remove turbolinks on your project

I had the same problem.

2 Comments

remove on your gemfile ?
removed from Gemfile, application.html.erb, application.js, uninstalled and server restarted
0

I solved the problem, I just added a jquery script in my application.html.erb that was the cause of the problem... Thanks everyone !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.