gpt4 book ai didi

ruby-on-rails - Rails 引擎扩展了 config/application.rb

转载 作者:数据小太阳 更新时间:2023-10-29 07:00:36 27 4
gpt4 key购买 nike

我正在编写一个 Rails 引擎,但我不确定如何扩展我的 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

最佳答案

对于 --full 和 --mountable 引擎

这将为您生成。

module engine_name
class Engine < ::Rails::Engine
end
end

在你的主应用程序中添加 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 选项相同的骨架结构,并将添加:

Assets list 文件(application.js 和 application.css)命名空间的 ApplicationController stub 命名空间的 ApplicationHelper stub 引擎的布局 View 模板命名空间隔离到 config/routes.rb:

关于ruby-on-rails - Rails 引擎扩展了 config/application.rb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20134687/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com