Why Use Gems for Serving Assets Instead of the Vendor File

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

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.

How to use the plugins within the vendor folder instead of the gems in rails?

Try, per the bundler doc:

gem [gem name], :path => [path]

Ex:

gem "rails", :path => "vendor/rails"

how to effectively organize vendor css and js files togheter in rails assets

in rails 4 they have removed vendor folder,so,assets will not server from vendor.

in that Rails.application.config.assets.paths not contains vendor,if you want you have to add the path like

in config/application.rb

config.assets.paths << "#{Rails.root}/vendor/assets"

rails assets in production not served (yet another assets issue)

this is my advise.

I add the following resources that may help in finding a solution.

https://launchschool.com/blog/rails-asset-pipeline-best-practices

https://railsapps.github.io/rails-javascript-include-external.html

https://reinteractive.com/posts/116-12-tips-for-the-rails-asset-pipeline

I read all the guides that can be found by searching rails asset pipeline, but I will not link them all

My advice is to check the fingerprint of the application.css and application.js both with the Chrome Developer Tools (by going in any screen element, opening the developer toolbox with f12 and checking any style of any div or any js file). You will need to check which fingerprint version of the file is used, then open that version with the text editor and check what is loaded in the fingerprint version of the file.

If your file (for ex. user.js) is loaded at the bottom of the manifest, you should easily find it at the bottom of your fingerprinted application.js.

If you want to update this file you can run

rake assets:precompile

This will precompile assets only in development, for production you need to specify the environment. It will change that fingerprinted file application.css and application.js with the editing you have done.

RAILS_ENV=production bundle exec rake assets:precompile

You can also check the file at the following address localhost:3000/assets/yourjsfile.js or check the fingerprint version by following localhost:3000/assets/application-yourfingerprint.js

As you can see, many files are included in that public/assets folder, you can delete them with rake assets:clean or -rf public/assets and then run rake assets:precompile, it will precompile again assets.

If nothing is included, then your application.js is not being loaded. You may try the following as I read on different posts:

  1. Include the file in the config/initializers/assets.rb with the following line of code:

    Rails.application.config.assets.precompile += %w( user.js )
  2. Start the rails c and run Rails.application.config.assets.paths
    This command will show in red the paths that are automatically included, for example those inside App, Lib and Vendor, in green those that you included by adding inside config/application.rb the follwing code to add new path

    config.assets.paths << Rails.root.join("vendor","assets", "fonts")

Another error i made in the past was not using the correct sprockets syntax, you can check it at the following link ( i was using require_user instead of require user):

https://github.com/rails/sprockets#sprockets-directives

Another problem was that I had under App/assets/javascript two files named user (user.coffee and user.js). The first to be loaded was user.coffee which was empty.

rails 4 asset pipeline vendor assets images are not being precompiled

It seems like images are included by default only from app/assets folder. So the solution is to add this line to config/application.rb

config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)

How to use index files inside vendor assets folders?

It turned out that the problem was in the library name. When I moved the library from

vendor/assets/libraries/jquery.ui

to

vendor/assets/libraries/jquery-ui

and replaced

//= require jquery.ui

with

//= require jquery-ui

everything started working properly, the index.js and index.sass files that are located inside the jquery-ui folder are now being loaded properly!

Install jQuery Rails 5.1 Yarn or Gem?

Adding "jquery-rails" to your gemfile allows you to use "jquery_ujs", which is a sort of "rails compatible" library : it allows you to (e.g) add a delete button / link that will delete your target just by specifiying method: delete as a parameter instead of creating a form. (link_to "delete", "foobar/delete", :method => 'delete' ).

Other than that, there's no much difference.



Related Topics



Leave a reply



Submit