Rails引擎扩展了config/application.rb

MZa*_*oza 7 ruby ruby-on-rails

我正在写一个Rails engine但我不知道如何扩展我的config/application.rb

我想我必须以任何方式得到应用程序名称的任何想法?

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module application_name
  class Application < Rails::Application
  end
end
Run Code Online (Sandbox Code Playgroud)

小智 2

对于 --full 和 --mountable 引擎

这将为您生成。

module engine_name
  class Engine < ::Rails::Engine
  end
end
Run Code Online (Sandbox Code Playgroud)

在您的主要应用程序 gemfile 中添加

gem 'engine_name', path: "/path/to/engine_name"

并在您的应用程序 config/routes.rb 文件中

mount engine_name::Engine, at: "/<mount_point_you_choose>"

http://guides.rubyonrails.org/engines.html

取自上面的链接...

--mountable 选项告诉生成器您想要创建一个“可安装”且与命名空间隔离的引擎。该生成器将提供与 --full 选项相同的骨架结构,并将添加:

资产清单文件(application.js 和 application.css) 命名空间的 ApplicationController 存根 命名空间的 ApplicationHelper 存根 引擎的布局视图模板 命名空间隔离到 config/routes.rb: