【发布时间】:2012-05-24 18:28:30
【问题描述】:
我正在处理一个包含三个不同应用程序的项目。他们应该共享一些模型和外部布局。为避免代码重复,我尝试将应用程序布局 (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 install(成功) - 将
gem 'common'放入项目Gemfile中
但项目仍然不会加载应用程序布局。我应该怎么做才能告诉我的项目必须通过 gem 加载布局文件?
提前致谢。
【问题讨论】:
-
如何使用 git 子模块或 svn 外部?如果你走 gem 路线,只要有变化,你就必须构建/安装。
-
@KreeK 子模块和外部是一种痛苦。根据我的经验,处理宝石更容易——只需运行
bundle install即可。尤其是 Git 子模块非常烦人。
标签: ruby-on-rails layout view gem gemspecs