【发布时间】:2015-07-25 02:33:32
【问题描述】:
全新的 Rails 4.2.3 应用程序。 Gemfile 的唯一更改是删除了 Spring,添加了 dotenv,以及 rubygems.org 上发布的最新的 contentful_rails 和 contentful_model gems。
由于未知原因,初始化程序中定义的配置细节在应用启动时已经消失。它是同一个对象(ContentfulModel.configuration.object_id 的值相同),但以前正确的值现在是 nil。
我添加了一个初始化器,如 README 中所示。
$ cat config/initializers/contentful_model.rb
ContentfulModel.configure do |config|
byebug
config.access_token = ENV['CONTENTFUL_ACCESS_TOKEN']
config.preview_access_token = ENV['CONTENTFUL_PREVIEW_ACCESS_TOKEN']
config.space = ENV['CONTENTFUL_SPACE']
# config.options = {
#extra options to send to the Contentful::Client
# }
end
我定义了一个模型,类别。
$ cat app/models/category.rb
class Category < ContentfulModel::Base
self.content_type_id = "[category content type string]"
end
所以当我启动 Rails 控制台时会发生以下情况:
$ rails c
[1, 9] in /home/trevor/code/chef/www-contentful-rails/config/initializers/contentful_model.rb
1: ContentfulModel.configure do |config|
2: config.access_token = ENV['CONTENTFUL_ACCESS_TOKEN']
3: config.preview_access_token = ENV['CONTENTFUL_PREVIEW_ACCESS_TOKEN']
4: config.space = ENV['CONTENTFUL_SPACE']
5: # config.options = {
6: #extra options to send to the Contentful::Client
7: # }
8: byebug
=> 9: end
(byebug) ContentfulModel.configuration
#<ContentfulModel::Configuration:0x00000005bc7be0 @access_token="[my actual token string]", @entry_mapping={}, @preview_access_token="[my actual preview token string]", @space="[my actual space]">
(byebug) continue
/home/trevor/.rvm/gems/ruby-2.2.2@www-contentful-rails/gems/actionpack-4.2.3/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::JSON
/home/trevor/.rvm/gems/ruby-2.2.2@www-contentful-rails/gems/actionpack-4.2.3/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of JSON was here
Loading development environment (Rails 4.2.3)
2.2.2 :001 > ContentfulModel.configuration
=> #<ContentfulModel::Configuration:0x00000005bc7be0 @access_token=nil, @entry_mapping={"[category content type string]"=>Category}, @preview_access_token=nil, @space=nil>
2.2.2 :002 >
我花了很多时间筛选 gem 源代码并单步调试调试器,但没有任何结果。我已经在 GitHub 上为该项目发布了 an issue,因为我无法确定问题的根源,我不得不假设它在 gem 中。非常欢迎任何有关如何进一步解决此问题的帮助!
【问题讨论】:
标签: ruby-on-rails ruby contentful