Where to put Galleria (jQuery image gallery framework) in Rails 3.1 Asset Pipeline?

前端 未结 3 1276

I\'m a bit confused as to where to put a jQuery framework like Galleria in Rails 3.1\'s new Asset Pipeline?

I know it, technically

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-28 21:03

    I had the same problem, and it took a while to get working. Initially, it would work fine on development, but when we moved to production, Galleria silently failed, due to the asset filenames now having "fingerprints". This also seems to be an issue with jQuery UI themes, and many other such scripts.

    Of course, you could just go back to the old way of doing things and throw everything in "public", but we would like the advantage of automatically merging all css/js files, and doing things the rails way.

    This is how I got it working:

    vendor/
      assets/
        images/
          classic-loader.gif
          classic-map.gif
        javascripts/
          galleria-1.2.5.js
          galleria.classic.js
        stylesheets
          galleria.classic.css.scss
    

    Rename your galleria.classic.css file to galleria.classic.css.scss. Then replace the image references, like so (I had two):

    url("classic-loader.gif") becomes image-url("classic-loader.gif")

    UPDATE: It looks like you don't need to do this in Rails 3.1.1. Just rename the file to .css.scss and rails will automatically preprocess the url() calls for you.

    In your app/assets/javascripts/application.js file, make sure you have the lines

    //= require galleria-1.2.5
    //= require galleria.classic
    //= require_tree .
    

    In you app/assets/stylesheets/application.css file, make sure you have the lines

    *= require galleria.classic
    *= require_tree .
    

    Finally, Galleria seems to have some fancy non-standard css loading built in. This is what was preventing Galleria from loading on our production website. Since we have already included the stylesheet, we want to disable this behavior. Simply open up galleria.classic.js (or your Galleria theme javascript file), and replace the line:

    css: 'galleria.classic.css',
    

    with:

    css: false,
    

    This will tell Galleria not to try loading the stylesheet.

    One more thing - when trying to compile these assets, I ran into what is apparently a bug in Rails 3.1.0. When I ran rake assets:precompile, I got errors like:

    $ bundle exec rake assets:precompile
    rake aborted!
    classic-loader.gif isn't precompiled
      (in /vendor/assets/stylesheets/galleria.classic.css.scss)
    

    Long story short, you need to set this line in config/environments/production.rb:

    config.assets.compile = true
    

    This shouldn't be necessary once 3.1.1 is released.

提交回复
热议问题