加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何将应用程序布局打包到Ruby gem中?

发布时间:2020-12-17 07:10:17 所属栏目:百科 来源:网络整理
导读:我正在开发一个包含三个不同应用程序的项目.他们应该分享一些模型和外部布局.为了避免代码重复,我正在尝试将应用程序布局(project_name / app / views / layouts / application.html.haml)解压缩到gem中. 我按照以下步骤操作: 使用bundle gem common创建基
我正在开发一个包含三个不同应用程序的项目.他们应该分享一些模型和外部布局.为了避免代码重复,我正在尝试将应用程序布局(project_name / app / views / layouts / application.html.haml)解压缩到gem中.

我按照以下步骤操作:

>使用bundle gem common创建基础gem结构
>将布局文件放在common / app / views / layouts / application.html.haml中
>写了Gemspec描述符

# -*- encoding: utf-8 -*-
require File.expand_path('../lib/common/version',__FILE__)

Gem::Specification.new do |gem|
  gem.authors       = ["Arthur Alkmim"]
  gem.email         = ["myemail@here"]
  gem.description   = %q{Common project files}
  gem.summary       = %q{Common project files,including layout and migrations}
  gem.homepage      = ""

  gem.files         = `git ls-files`.split($)
  gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
  gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
  gem.name          = "common"
  gem.require_paths = ["lib"]
  gem.version       = Common::VERSION
end

>提交更改
> gem build common.gemspec(成功)
> rake安装(成功)
>将gem’common’放置在项目Gemfile中

但是项目仍然不会加载应用程序布局.我该怎么做才能告诉我的项目它必须通过gem加载布局文件?

提前致谢.

解决方法

您是否已将宝石添加到Rails Gemfile中以将其包含在您的应用程序中?

您可以使用path选项指定开发中的相对路径.例如

gem 'common',:path => "../path/to/gem"

不要忘记然后运行bundle install

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读