Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including external libraries using the Rails 3.1 asset pipeline

Background: I wish to use freebase suggest in my app.

I intend to add an autocomplete to the #location input using coffeescript:

$ ->
  $("#location").suggest type: "location"

Which will be included by the asset pipeline at require_tree in my application.js file:

//= require jquery
//= require jquery_ujs
//= require modernizr
//= require_tree .

Must I copy suggest.min.js to app/assets/javascripts and require it as

//= require suggest.min

or can I require it directly from its publicly available url?

like image 483
Alec Wenzowski Avatar asked Aug 29 '11 20:08

Alec Wenzowski


People also ask

What is assets pipeline in Rails?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass, and ERB.

What does Rails assets Precompile do?

The Rails asset pipeline provides an assets:precompile rake task to allow assets to be compiled and cached up front rather than compiled every time the app boots. There are two ways you can use the asset pipeline on Heroku. Compiling assets locally.

What is Require_self?

//= require_self. It loads the file itself, to define the order that the files are loaded.

What are Rails Sprockets?

Sprockets is a Ruby library for compiling and serving web assets. Sprockets allows to organize an application's JavaScript files into smaller more manageable chunks that can be distributed over a number of directories and files.


1 Answers

You can always get it from the CDN by putting it in a view or template.

<%= javascript_include_tag "http://freebaselibs.com/static/suggest/1.3/suggest.min.js" %>
like image 176
cmpolis Avatar answered Nov 09 '22 23:11

cmpolis