【问题标题】:How can I have a dependency for HAML in my gem when the project doesn't have HAML当项目没有 HAML 时,如何在我的 gem 中依赖 HAML
【发布时间】:2011-10-29 10:47:30
【问题描述】:

我可以在我的 gem 中使用 Haml 模板,而无需在应用程序 Gemfile 中写入 gem 'haml'

我在 my_gem.gemspec 文件中放入了这一行:

s.add_runtime_dependency "haml", "~> 3.0"

我将这一行放在 my_gem 文件夹的 Gemfile 中:

gem 'haml', '~> 3.0'

我做:bundle, and Haml install at this moment ,但它不起作用,我有

Template is missing
Missing template layouts/my_gem with {:handlers=>[:erb, :builder, :coffee] }

仅当我在应用程序 Gemfile 中复制时

gem 'haml', '~> 3.0'

一切正常。

我可以将 Haml 与我的 gem 一起使用而不复制到 Gemfile 中吗?

【问题讨论】:

  • 解决方案是:需要 'haml' 进入 My_gem.rb。任何应用程序(引擎)都应该需要所有需要的 gems

标签: ruby-on-rails-3 dependencies gem haml gemfile


【解决方案1】:

任何应用程序(引擎)都应该需要所有需要的 gem,例如对我来说:

require "haml"

require "the_role/hash"
require "the_role/engine"
require "the_role/version"
require "the_role/the_class_exists"

module TheRole
  # some code here
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多