Getting Start With Rails Engine

Load Engine

Gemfile

1
gem 'enginename',    :path => "./engines/enginename"

config/application.rb

1
config.paths['db/migrate'] << 'engines/engine_name/db/migrate'

app/assets/stylesheets/application.css

1
*= require engine_name/application

app/assets/javascripts/application.js

1
//= require engine_name/application

load engine routes, config/routes.rb

1
mount EngineName::Engine => "/engine_name"

Configure Engine

configure engine's generator

lib/engine_name/engine.rb

1
2
3
4
5
config.generators do |g|
  g.test_framework  :test_unit, :fixture_replacement => :factory_girl
  g.javascripts = false
  g.helper = true
end

require libs

lib/engine_name/engine.rb

1
require 'your gems in Gemfile'

using the layout of main_app

vi app/controllers/enginename/applicationcontroller.rb

1
layout 'layouts/application'

linkto mainapp's url

1
link_to 'main app url', main_app.some_url

test functional with use_route

1
get :path, :use_route=>:engine_name

add code to mainapp's applicationcontroller

1
2
3
ActiveSupport.on_load(:action_controller) do
  #do something  
end