0

There is the following question: I have some shared JS function in shared.js.coffee module. I want to use these functions, for example, in module some_actions.js.coffee. So, but I don't know how I should share functions in the first module properly. Please, give me advice to do it well. Thanks.

malcoauri
  • 11,904
  • 28
  • 82
  • 137

1 Answers1

0

In these situations it is best to use the Paloma gem (https://github.com/kbparagua/paloma) and use it whenever required, for example, use it like so :

gem 'paloma'

You can then code this is in application.js or shared.js.coffee but make sure that you have

//= require shared.js.coffee

in your application.js. And then you con do like this :

var UsersController = Paloma.controller('Users');

// Executes when Rails User#new is executed.
UsersController.prototype.new = function(){
   alert('Hello User!' );
};

In your controller :

def UsersController < ApplicationController
    def new
      # a Paloma request will automatically be created.
      @user = User.new
    end
end

I think this should help you understand.

Sankalp Singha
  • 4,461
  • 5
  • 39
  • 58