Why use gems for serving assets instead of the vendor file?

前端 未结 4 1110
余生分开走
余生分开走 2021-01-21 19:12

I am relatively new to Rails and I have a question about serving assets from a gem vs just loading the files into the asset pipeline.

As far as I can tell, they do virtu

相关标签:
4条回答
  • 2021-01-21 19:52

    The advantage is you don't have to add the file(s) to your repo and manage updates, you update the gem and you've updated the dependency. They can also add helpers to use the assets more easily.

    Not all JS/CSS projects are out-of-the-box compatible with the asset pipeline too, so sometimes the gems will do that work for you as well.

    Just because the files get served to clients doesn't make it much different than any other dependency in your application.

    0 讨论(0)
  • 2021-01-21 20:02

    jquery-rails is gem contains js file for both jquery.js, jquery_ujs.js. If you does not include jquery-rails, then you have include both jquery.js and jquery_ujs.js.If you are not using gem for jquery-rails, you have manually keep track what version jquery.js is used for jquery_ujs.js. Currently these dependency management is taken care by gem 'jquery-rails'.

    0 讨论(0)
  • 2021-01-21 20:05

    The gem includes the unobtrusive javascript for Rails as well as jQuery itself. It also allows you to user assert_select_jquery in tests.

    0 讨论(0)
  • 2021-01-21 20:08

    Benefits:

    1. You don't need to manually copy them when you get a new version of jquery released, gem will make sure to add the latest codes only.

    2. Check this link: https://github.com/rails/jquery-rails/blob/master/lib/jquery/assert_select.rb#LC48 It provides couple of methods which helps while testing your code.

    0 讨论(0)
提交回复
热议问题