Reputation: 8185
I want to write a ruby gem, when installed in a rails app, introduces the javascript method .foo() So I will be able to do $(body).foo() or $(any-dom-element).foo()
How do I go about doing this?
So far what I've done:
Added this to my main rails app:
gem "foo", path: "~/foo"
Wrote the code for the foo() method
// file ~/foo/lib/assets/javascripts/foo.js
// https://learn.jquery.com/plugins/basic-plugin-creation/
$.fn.foo = function() {
this.css( "color", "green" );
};
//$( "a" ).foo(); // Makes all the links green.
Added a require statement in the main rails app
// app/assets/javascripts/application.js
//= require foo
Upvotes: 0
Views: 23
Reputation: 8185
Alright I figured it out. Halfway through doing it, I found a great article about it.
instead of writing all the steps I did, I'm going to post a link to the article which gives step by step instructions
Upvotes: 1