This gem packages the jQuery UI assets (JavaScripts, stylesheets, and images) for the Rails asset pipeline, so you never have to download a custom package through the web interface again.
See VERSIONS.md to see which versions of jquery-ui-rails bundle which versions of jQuery UI.
Warning: This gem is incompatible with the jquery-rails
gem before version
3.0.0! Strange things will happen if you use an earlier jquery-rails
version. Run bundle list
to ensure that you either aren't using
jquery-rails
, or at least version 3.0.0 of jquery-rails
.
In your Gemfile, add:
gem 'jquery-ui-rails'
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
*/
Warning: If you are using a version below 5.0, you will have to use a different naming for the files to require, see https://github.com/joliss/jquery-ui-rails/blob/v4.2.1/README.md for more information.
All images required by jQuery UI are automatically served through the asset pipeline, so you are good to go! For example, this code will add a datepicker:
$(function() {
$('.datepicker').datepicker();
});
The jQuery UI code weighs 51KB (minified + gzipped) and takes a while to execute, so for production apps it's recommended to only include the modules that your application actually uses. Dependencies are automatically resolved. Simply pick one or more modules from the asset list below.
For example, if you only need the datepicker module, add this to your application.js:
//= require jquery-ui/datepicker
In your application.css, require the corresponding CSS module:
/*
*= require jquery-ui/datepicker
*/
//= require jquery-ui/core
//= require jquery-ui/widget
//= require jquery-ui/mouse
//= require jquery-ui/position
You usually do not need to require these directly, as they are pulled in by the other JavaScript modules as needed.
//= require jquery-ui/draggable
//= require jquery-ui/droppable
//= require jquery-ui/resizable
//= require jquery-ui/selectable
//= require jquery-ui/sortable
For all but jquery-ui/droppable
, remember to require
their matching CSS
files in your application.css as well.
//= require jquery-ui/accordion
//= require jquery-ui/autocomplete
//= require jquery-ui/button
//= require jquery-ui/datepicker
//= require jquery-ui/dialog
//= require jquery-ui/menu
//= require jquery-ui/progressbar
//= require jquery-ui/selectmenu
//= require jquery-ui/slider
//= require jquery-ui/spinner
//= require jquery-ui/tabs
//= require jquery-ui/tooltip
For all of these, remember to require
their matching CSS files in your
application.css as well.
Datepicker has optional i18n modules for non-US locales, named
jquery-ui/datepicker-xx[-YY]
(list),
for example:
//= require jquery-ui/datepicker
//= require jquery-ui/datepicker-pt-BR
Note that you still need to include the main datepicker module. It is not required automatically for performance reasons.
//= require jquery-ui/effect.all
//= require jquery-ui/effect
//= require jquery-ui/effect-blind
//= require jquery-ui/effect-bounce
//= require jquery-ui/effect-clip
//= require jquery-ui/effect-drop
//= require jquery-ui/effect-explode
//= require jquery-ui/effect-fade
//= require jquery-ui/effect-fold
//= require jquery-ui/effect-highlight
//= require jquery-ui/effect-puff
//= require jquery-ui/effect-pulsate
//= require jquery-ui/effect-scale
//= require jquery-ui/effect-shake
//= require jquery-ui/effect-size
//= require jquery-ui/effect-slide
//= require jquery-ui/effect-transfer
/*
*= require jquery-ui/core
*= require jquery-ui/theme
*/
You might want to require these if you do not use any of the following modules, but still want jQuery UI's basic theming CSS. Otherwise they are automatically pulled in as dependencies.
/*
*= require jquery-ui/draggable
*= require jquery-ui/resizable
*= require jquery-ui/selectable
*= require jquery-ui/sortable
*/
/*
*= require jquery-ui/accordion
*= require jquery-ui/autocomplete
*= require jquery-ui/button
*= require jquery-ui/datepicker
*= require jquery-ui/dialog
*= require jquery-ui/menu
*= require jquery-ui/progressbar
*= require jquery-ui/selectmenu
*= require jquery-ui/slider
*= require jquery-ui/spinner
*= require jquery-ui/tabs
*= require jquery-ui/tooltip
*/
For bugs in jQuery UI itself, head to the jQuery UI Development Center.
For bugs in this gem distribution, use the GitHub issue tracker.
The jquery-ui-rails
gem should work in Ruby 1.8.7 apps. To run the rake
tasks, you need Ruby 1.9 however.
git clone git://github.com/joliss/jquery-ui-rails.git
cd jquery-ui-rails
git submodule update --init
bundle install
bundle exec rake # rebuild assets
Most of the code lives in the Rakefile
. Pull requests are more than welcome!
The jquery-ui-rails repository is contributor-friendly and has a git submodule containing the official jquery-ui repo. This way it's easy to hack the jQuery UI code:
cd jquery-ui
git checkout master # or 1-8-stable
... hack-hack-hack ...
bundle exec rake # rebuild assets based on your changes
Assuming your app's Gemfile points at your jquery-ui-rails checkout (gem 'jquery-ui-rails', :path => '~/path/to/jquery-ui-rails'
), all you need to do
now is refresh your browser, and your changes to jQuery UI are live in your
Rails application.
You can send pull requests to the jquery-ui GitHub project straight out of your submodule. See also their Getting Involved guide.
As a smoke test, a testapp
application is available in the repository, which
displays a check mark and a datepicker to make sure the assets load correctly:
cd testapp
bundle install
rails server
Now point your browser at http://localhost:3000/.
Be sure that VERSIONS.md
, History.md
and lib/jquery/ui/rails/version.rb
are up-to-date. Then build and push like so:
rake build
gem push pkg/jquery-ui-rails-X.Y.Z.gem
git tag vX.Y.Z
git push --tags
-
Only the base theme (Smoothness) is included. Once it becomes possible to generate all theme files from the jQuery UI sources, we can package all the other themes in the ThemeRoller gallery.
Perhaps we can also add helper tasks to help developers generate assets for their own custom themes or for third-party themes (like Selene).
If you still want a different theme right now, you could probably download a custom theme and require the theme CSS after requiring any other jQuery UI CSS files you need, making sure to serve up the theme images correctly. (This is arguably cumbersome, not officially supported by this gem, and adds 1 KB overhead as both the base theme and the custom theme are served up.)