Skip to content

Manual Installation (gem less)

kpheasey edited this page Sep 10, 2014 · 3 revisions

Create base.js.coffee

# app/assets/javascripts/base.js.coffee
window.App ||= {}
class App.Base

  constructor: ->
    return this

  create: ->
    $this.new()
    return

  update: ->
    $this.edit()
    return

Create ```global.js.coffee``

# app/assets/javascripts/global.js.coffee
window.App ||= {}

Include base before the javascripts tree

# app/assets/javascripts/application.js
.
.
.
//= require jquery
.
.
.
//= require base
//= require tree.

Initialize and call the current controller action's matching class and function from the application layout. Add the following just before the closing body tag.

For ERB:

<script>
  jQuery(function() {
    window.$this = new (App.<%= controller_path.split(/\/|_/).map(&:capitalize).join('') %> || App.Base)();
    if (typeof $this.<%= action_name %> === 'function') {
      return $this.<%= action_name%>.call();
    }
  });
</script>

For HAML:

:javascript
  jQuery(function() {
    window.$this = new (App.#{controller_path.split(/\/|_/).map(&:capitalize).join('')} || App.Base)();
    if (typeof $this.#{action_name} === 'function') {
      return $this.#{action_name}.call();
    }
  });

Clone this wiki locally