全新的Rails 4.2.3应用程序。对Gemfile的唯一更改是删除了Spring,添加了dotenv,以及rubygems.org上发布的最新contentful_rails和contentful_model宝石。
由于未知原因,初始化程序中定义的配置详细信息在应用程序启动时消失。它是同一个对象(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 >
我花了很多时间来筛选宝石源并踩过调试器而没有结果。我已经在GitHub上发布了an issue项目,因为我无法确定问题的根源,我必须假设它在gem中。任何有关如何进一步排除故障的协助都将非常受欢迎!
答案 0 :(得分:0)
solution使用changes a few months ago所需的未记录方法。
contentful_rails gem 需要 contentful_model(反之亦然),而contentful_model的唯一配置文档就在该项目的README中,描述了我的问题中的方法。当初始化contentful_rails时,以这种方式进行的配置被完全擦除,这预计配置将在其自己的初始化器中完成。
所以我删除了config / initializers / contentful_model.rb,现在我的config / intializers / contents_rails.rb文件如下:
ContentfulRails.configure do |config|
config.authenticate_webhooks = true # false here would allow the webhooks to process without basic auth
config.webhooks_username = ENV['CONTENTFUL_WEBHOOK_USERNAME']
config.webhooks_password = ENV['CONTENTFUL_WEBHOOK_PASSWORD']
config.access_token = ENV['CONTENTFUL_ACCESS_TOKEN']
config.preview_access_token = ENV['CONTENTFUL_PREVIEW_ACCESS_TOKEN']
config.space = ENV['CONTENTFUL_SPACE']
config.contentful_options = {
#extra options to send to the Contentful::Client
}
end
值得注意的是config.options不再是一个东西;它的config.contentful_options。