Ruby on Rails 3.1 and jQuery UI images

前端 未结 18 986
无人及你
无人及你 2020-12-12 11:50

I\'m using Ruby on Rails (Edge, the development version), and Ruby rvm 1.9.2.

application.js is as follows.

//= require jquery
//= requi         


        
18条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 12:17

    With Ruby on Rails 3.1.2 I did the following.

    #app/assets/javascripts/application.js
    
    //= require jquery
    //= require jquery_ujs
    //= require jquery-ui
    //= require_tree .
    

    For the CSS files, I like to do @import instead to have more control over the load order of CSS files. To do this, I have to add the .scss extension to the app/assets/stylesheets/application.css file, and also to all CSS files I want to import, like the jQuery UI CSS file.

    #app/assets/stylesheets/application.css.scss
    
    /*
    * This is a manifest file that'll automatically include all the stylesheets available in this directory
    * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
    * the top of the compiled file, but it's generally better to create a new file per style scope.
    *= require_self
    */
    
    @import "jquery-ui/ui-lightness/jquery-ui-1.8.16.custom.css.scss";
    
    /* Other css files you want to import */
    @import "layout.css.scss";
    @import "home.css.scss";
    @import "products.css.scss";
    ....
    

    Then I put everything jQuery UI related in vendor/assets like this:

    jQuery UI stylesheet:

    vendor/assets/stylesheets/jquery-ui/ui-lightness/jquery-ui-1.8.16.custom.css.scss
    

    jQuery UI images folder:

    vendor/assets/images/images
    

    Note that you can create additional folder in the stylesheets path like I did here with "jquery-ui/ui-lightness" path. That way you can keep multiple jQuery themes nicely separated in their own folders.

    ** Restart your server to load any newly created load paths **

    Ryan Bates has some excellent screencasts about the asset pipeline and Sass in Ruby on Rails 3.1, where he shows how to use the @import function in Sass. Watch it here:

    • #279 Understanding the Asset Pipeline

    • #268 Sass Basics

    Edit: I forgot to mention that this works both locally and on Heroku on the Cedar stack.

提交回复
热议问题