全新的 Rails 4.2.3 应用程序。Gemfile 的唯一更改是删除 Spring、添加 dotenv 以及 rubygems.org 上发布的最新 contentful_rails和contentful_model gem。
由于未知原因,初始化程序中定义的配置细节在应用程序启动时已经消失。它是同一个对象(相同的值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 上发布了该项目的问题,因为我无法确定问题的根源,我必须假设它在 gem 中。任何有关如何进一步解决此问题的帮助都将非常受欢迎!