Skip to content

Advanced Re usable Frontend

TheNotary edited this page Feb 5, 2016 · 1 revision

Frontend assets like css and javascript can be bundled into packages and used .

The advantages of this are:

  • The frontend code becomes easy to re-use in other apps
  • Updating frontend libraries becomes as simple as typing bundle update rails-assets-jquery
  • The frontend code doesn't need to be version controlled directly in the host repository

How to Use a Rails-Assets Package

Basically just search (https://rails-assets.org/)[rails-assets] for a package you're interested in and follow their instructions.

So the first step to using a rails-assets package is to pick a package to use from the internet. Let's start with jquery since it's popular. When you search rails-assets.org, it shows you the first hit, and tells you that you need to add gem 'rails-assets-jquery' to your project's Gemfile, and you then need to add //= require jquery to your javascript manifest file to include jquery on all the pages of your rails app. (PS anytime you add something to your Gemfile, you need to run bundle install to install it and then restart the server)

Because the main github repo for jquery is a valid bower package (it has a package.json file in it's root) rails-assets is able to automatically read the git repo (and it's release tags) and make it available to rails apps in this manor.

Clone this wiki locally