[go: up one dir, main page]

Skip to content
afmelo edited this page Dec 3, 2014 · 12 revisions

Creating an engine or extension

rails plugin new vendor/engines/[engine_name] --full

Creating init.rb in engine_name folder

require 'weby'
::Weby::registe_extension(Weby::Extension.new(:engine_name, author: 'Cercomp - Equipe Web', settings: [:text]))

Update informations on vendor/engines/engine_name.gemspec

Execute bundle install

Configuring engine.rb

In engine_name folder, open engine.rb file (in lib/engine_name)

module engine_name

class Engine < ::Rails::Engine

Add the lines below
    mod = engine_name
    engine_name(generate_railtie_name(mod.name))
    self.routes.default_scope = {}
    self.isolated = true
    unless mod.respond_to?(:railtie_namespace)
      name, railtie = engine_name, self
      mod.singleton_class.instance_eval do
        define_method(:railtie_namespace) { railtie }
        unless mod.respond_to?(:table_name_prefix)
          define_method(:table_name_prefix) { "#{name}_" }
        end
        unless mod.respond_to?(:use_relative_model_naming?)
          class_eval "def use_relative_model_naming?; true; end", __FILE__, __LINE__
        end
      end
    end

Creating routes

To define routes, create a routes.rb file in vendor/engines/[engine_name]/lib/[engine-name]