【问题标题】:rails engine gemfile.lock not being included rails enginerails engine gemfile.lock 不被包含 rails engine
【发布时间】:2019-05-23 08:28:08
【问题描述】:

我正在尝试构建一个 Rails 引擎,并且我有一些我想隔离并仅在 Rails 引擎 Gemfile 中捆绑的 gem。我把这些宝石放在我的Gemfile

source 'https://rubygems.org'
gemspec
gem "pg", "0.15"

在我的 insurance.gemspec 中:

$:.push File.expand_path("../lib", __FILE__)

# Maintain your gem's version:
require "insurance/version"

# Describe your gem and declare its dependencies:
Gem::Specification.new do |spec|
  spec.name        = "insurance"
  spec.version     = Insurance::VERSION
  spec.authors     = ["Engine Sample"]
  spec.email       = ["engine@engine.com"]
  spec.homepage    = "https://github.com/engine/engine_plugin"
  spec.summary     = "Engine Sample."
  spec.description = "Engine Sample."
  spec.license     = "MIT"

  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
  # to allow pushing to a single host or delete this section to allow pushing to any host.
  if spec.respond_to?(:metadata)
    spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
  else
    raise "RubyGems 2.0 or newer is required to protect against " \
      "public gem pushes."
  end

  spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]

  spec.add_dependency "rails", "~> 5.0.1"
  spec.add_development_dependency "route_translator"
end

然后我转到终端上的引擎并运行bundle install,这会在我的引擎文件夹中生成Gemfile.lock

然后我转到主应用程序并在主应用程序 Gemfile 中添加:

gem 'insurance', path: '/home/Documents/Projects/insurance'

我还在我的引擎文件夹config/routes.rb中创建了一些路由

但是当我运行我的应用程序时,我得到了这个错误

Gem::LoadError - pg is not part of the bundle. Add it to your Gemfile.:

【问题讨论】:

    标签: ruby-on-rails rubygems rails-engines


    【解决方案1】:

    Rails 引擎实际上是 gem,它们应该依赖于父应用的 Gemfile.lock,并且只在其 gemspec 中指定依赖项。

    如果您希望某个 gem 成为引擎的依赖项 - 然后将其添加到 gemspec,如果您想锁定确切的版本 - 在依赖项声明中执行此操作(但实际上,最好指定一个更宽松的版本) :

    spec.add_dependency "pg", "0.15" # better use something like "~>0.15" here
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多