Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add jQuery plugins on my rails app

I will use the GMAP3 Plugin for JQuery in my rails app.

I already put the javascript file in app/assets/javascripts/gmap3/gmap3.min.js.

I will use this jQuery plugin only on the welcome page. What files do I need to modify (and how) in order to make use the plugin?

like image 376
Efe Avatar asked Oct 04 '22 16:10

Efe


1 Answers

You should put the file ( for a Rails 3 project ) in vendor/assets/javascripts/gmap3.min.js and then you should add it in two ways:

<%= javascript_include_tag 'gmap3.min' %>

or in some added file like

//In (for example) application.js

//= require gmap3.min

If you added the file correctly, that is, in a page that you are seeing (you can check this in your browser console, usually in Resources or Network ), you can use it.

Some links for you to see:

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

  • http://railscasts.com/episodes/279-understanding-the-asset-pipeline?view=asciicast

like image 81
nicosantangelo Avatar answered Oct 07 '22 18:10

nicosantangelo