gpt4 book ai didi

ruby-on-rails - Rails 3.1 可安装的引擎 gem 依赖项

转载 作者:行者123 更新时间:2023-12-04 06:00:16 25 4
gpt4 key购买 nike

我正在为我的应用程序使用 api。
api 是一个可安装的引擎。

我的问题是,如果在父应用程序 gemfile 中未指定 gem,则它们不会加载到 api 引擎中。

我目前的设置:

父应用程序/Gemfile

gem 'api', :path => 'path/to/api'

parentapp/routes.rb
mount Api::Engine => '/api'

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

require "api/version"

Gem::Specification.new do |s|
s.name = "api"
s.version = Api::VERSION
s.authors = ["Author"]
s.email = ["email"]
s.homepage = "http://example.com"
s.summary = "Summary"
s.description = "Description"

s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]

# Is not loading.
s.add_dependency 'rails', '~> 3.1.3'
s.add_dependency 'rabl'
s.add_dependency 'yajl-ruby'
end

api/test/dummy/config/routes.rb
Rails.application.routes.draw do

mount Api::Engine => "/api"
end

奇怪的是它正在“加载”,因为如果我设置
s.add_dependency 'rails', '~> 3.2'

它引发了一个错误。

如果我删除了堆栈跟踪 gem 'rabl'来自父应用程序 gemfile。
NameError: uninitialized constant Rabl
~/Sites/api/config/initializers/rabl_init.rb:1:in `<top (required)>'
~/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/engine.rb:556:in `block (2 levels) in <class:Engine>'
~/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/engine.rb:555:in `each'
~/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/engine.rb:555:in `block in <class:Engine>'
~/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:30:in `instance_exec'
~/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:30:in `run'
~/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:55:in `block in run_initializers'
~/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:54:in `each'
~/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:54:in `run_initializers'
~/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/application.rb:96:in `initialize!'
~/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
~/Sites/parentapp/config/environment.rb:5:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
~/Sites/parentapp/config.ru:3:in `block in <main>'
~/Library/Application Support/Pow/Versions/0.3.2/node_modules/nack/lib/nack/builder.rb:4:in `instance_eval'
~/Library/Application Support/Pow/Versions/0.3.2/node_modules/nack/lib/nack/builder.rb:4:in `initialize'
~/Sites/parentapp/config.ru:1:in `new'
~/Sites/parentapp/config.ru:1:in `<main>'
~/Library/Application Support/Pow/Versions/0.3.2/node_modules/nack/lib/nack/server.rb:50:in `eval'
~/Library/Application Support/Pow/Versions/0.3.2/node_modules/nack/lib/nack/server.rb:50:in `load_config'
~/Library/Application Support/Pow/Versions/0.3.2/node_modules/nack/lib/nack/server.rb:43:in `initialize'
~/Library/Application Support/Pow/Versions/0.3.2/node_modules/nack/lib/nack/server.rb:13:in `new'
~/Library/Application Support/Pow/Versions/0.3.2/node_modules/nack/lib/nack/server.rb:13:in `run'
~/Library/Application Support/Pow/Versions/0.3.2/node_modules/nack/bin/nack_worker:4:in `<main>'

这是我的 rabl_init.rb 文件,位于 config/initializers(在引擎中)
Rabl.configure do |config|
config.include_json_root = false
end

如果我删除这个文件,我会得到 Template is missing
Missing template api/v1/myresource/show, api/application/show with {:handlers=>[:erb, :builder, :coffee, :haml], :formats=>[:json]

不包括 rabl 处理程序,因此,未加载 rabl。

最佳答案

我没有像我应该的那样需要 gem 。
添加 require "rabl"lib/api/engine.rb解决了。

关于ruby-on-rails - Rails 3.1 可安装的引擎 gem 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9001622/

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