Creating game we begin with preparing our rails env. This will be a simple mountable rails engine with multiplayer server written using eventmachine.

We will start with generating rails engine without active record, action view and test unit:

$ rails plugin new macbury_ninja --skip-active-record --skip-action-view --skip-test-unit

create  README.rdoc
create  Rakefile
create  macbury_ninja.gemspec
create  .gitignore
create  Gemfile
create  app/models
create  app/models/.keep
create  app/controllers
create  app/controllers/.keep
create  app/views
create  app/views/.keep
create  app/helpers
create  app/helpers/.keep
create  app/mailers
create  app/mailers/.keep
create  app/assets/images/macbury_ninja
create  app/assets/images/macbury_ninja/.keep
create  config/routes.rb
create  lib/macbury_ninja.rb
create  lib/tasks/macbury_ninja_tasks.rake
create  lib/macbury_ninja/version.rb
create  lib/macbury_ninja/engine.rb
create  app/assets/stylesheets/macbury_ninja
create  app/assets/stylesheets/macbury_ninja/.keep
create  app/assets/javascripts/macbury_ninja
create  app/assets/javascripts/macbury_ninja/.keep
create  bin
create  bin/rails
   run  bundle install

This will create macbury_ninja directory with required files. After this we can add engine to our rails application. We do it by adding to Gemfile line like this:

group :development, :test do
  gem "macbury_ninja", path: "/home/macbury/Projects/macbury_ninja"

First we add name of generated engine(mostly is the same as directory of engine, but if you are not sure, check .gemspec file), path parameter points to directory with our engine. With this we don’t need to build each time a gem.

Now we need add phaser.js to our application. Thankfully there is a gem with phaser.js for rails asset pipeline:

Simply add it to engine gemspec file and bundle your rails application.

$:.push File.expand_path("../lib", __FILE__)

# Maintain your gem's version:
require "macbury_ninja/version"

# Describe your gem and declare its dependencies: do |s|        = "macbury_ninja"
  s.version     = MacburyNinja::VERSION
  s.authors     = ["macbury"]       = ["[email protected]"]
  s.homepage    = ""
  s.summary     = "Simple Game"
  s.description = "Simple Game"
  s.license     = "MIT"

  s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]

  s.add_dependency "rails", "~> 4.1.4"
  s.add_dependency "phaser-rails", "~>" # Add here phaser gem

Rails don’t require automatically libraries from rails engine gemspec. We need to do it manually. The simplest way is to add require to engine lib/engine_name.rb file which for us should look like lib/macbury_ninja.rb:

require "macbury_ninja/engine"
require "phaser/rails" # Added here phaser

module MacburyNinja

Create now file game.js in engine app/assets/javascripts/macbury_ninja/ with required phaser.js:

//= require phaser

Finally we should be able to add our game file to our main rails application.js file:

//= require jquery
//= require jquery_ujs
//= require macbury_ninja/game