Rails 4: Where to put JavaScript/CSS plugins

前端 未结 3 598
执念已碎
执念已碎 2021-01-20 03:40

I have Rails 4rc1 application. I need to integrate some JavaScript / CSS plugins / 3rd party libraries/ to my application. I know vendor/plugins directories are deprecated i

相关标签:
3条回答
  • 2021-01-20 03:50

    Extract your vendor/plugins to their own gems and bundle them in your Gemfile. If they're tiny, not worthy of the own gem, fold it into your app as lib/myplugin/* and config/initializers/myplugin.rb.

    0 讨论(0)
  • 2021-01-20 03:57

    Rails 4.0 no longer supports loading plugins from vendor/plugins. You must replace any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, lib/my_plugin/* and add an appropriate initializer in config/initializers/my_plugin.rb.

    http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0-vendor-plugins

    You could of course move the javascript libraries to anywhere in your app/assets/ folder.

    0 讨论(0)
  • 2021-01-20 04:13

    It sounds like you may be asking about third-party javascripts & CSS - not Rails plugins. I prefer to put my third-party scripts under vendor/assets, like so:

    RAILS_ROOT
      \- vendor
        \- assets
          \- javascripts
           - stylesheets
    

    Then you can access them in your application.* files like this:

    // application.js
    //= require_tree vendor/javascripts
    
    /* application.css */
    *= require vendor
    
    0 讨论(0)
提交回复
热议问题