使用 Rpush 将推送通知添加到我的 rails 3 应用程序时出错
Posted
技术标签:
【中文标题】使用 Rpush 将推送通知添加到我的 rails 3 应用程序时出错【英文标题】:Error adding push notifications to my rails 3 app using Rpush 【发布时间】:2015-03-07 03:40:07 【问题描述】:我将 rpush gem 添加到我的 gemfile 并运行 bundle install。根据文档,下一步是运行 rpush init。这给了我以下错误。
You did not specify how you would like Rails to report deprecation notices for your init environment, please set config.active_support.deprecation to :log, :notify or :stderr at config/environments/init.rb
/Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in
resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in
resolve_string_connection'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in spec'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in
establish_connection'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/railtie.rb:82:in block (2 levels) in <class:Railtie>'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in
instance_eval'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in execute_hook'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:26:in
block in on_load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:25:in each'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:25:in
on_load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/railtie.rb:74:in block in <class:Railtie>'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/initializable.rb:30:in
instance_exec'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/initializable.rb:30:in run'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/initializable.rb:55:in
block in run_initializers'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/initializable.rb:54:in each'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/initializable.rb:54:in
run_initializers'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/application.rb:136:in initialize!'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in
method_missing'
from config/environment.rb:5:in <top (required)>'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in
load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in block in load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in
load_dependency'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/rpush-1.0.0/bin/rpush:31:in
'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/bin/rpush:23:in load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/bin/rpush:23:in
'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in eval'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in
'
然后我将一个 init.rb 文件添加到我的环境文件夹中,该文件遵循错误提示。这是我添加到 init.rb 的内容
CityRails::Application.configure do
config.active_support.deprecation = :log
end
然后我再次运行 rpush init 并收到以下错误
/Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in
resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in
resolve_string_connection'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in spec'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in
establish_connection'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/railtie.rb:82:in block (2 levels) in <class:Railtie>'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in
instance_eval'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in execute_hook'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:26:in
block in on_load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:25:in each'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:25:in
on_load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-3.2.13/lib/active_record/railtie.rb:74:in block in <class:Railtie>'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/initializable.rb:30:in
instance_exec'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/initializable.rb:30:in run'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/initializable.rb:55:in
block in run_initializers'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/initializable.rb:54:in each'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/initializable.rb:54:in
run_initializers'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/application.rb:136:in initialize!'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in
method_missing'
from config/environment.rb:5:in <top (required)>'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in
load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in block in load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in
load_dependency'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/gems/rpush-1.0.0/bin/rpush:31:in
'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/bin/rpush:23:in load'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/bin/rpush:23:in
'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in eval'
from /Users/mcarthur/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in
'
请帮忙。我已经为此工作了3天。你们太棒了。
编辑:我将 sqlite3 用于测试/开发环境,将 pg 用于生产。
这就是我的 database.yml 的样子:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: postgresql
encoding: unicode
database: cityrails_production
pool: 5
本地 rake db:migrate 的输出 -
database: /Users/mcarthur/Desktop/apps/city-rails/db/development.sqlite3
状态迁移 ID 迁移名称
up 20140423191412 创建用户 向上 20140423191450 创建联系人 up 20140423191657 创建场地 up 20140423191730 创建城市 up 20140423194439 建立友谊 up 20140423212732 创建邀请 up 20140423212915 添加默认邀请状态 向上 20140423213804 创建 kptwilios up 20140423221018 创建推送通知 up 20140423221315 创建设备令牌 up 20140423221356 添加默认到设备令牌环境 up 20140423225205 创建延迟的工作 up 20140430001800 添加用户ID到场所 up 20140430001824 添加json信息到场地 up 20140616234552 添加api id到场地 up 20140617012705 将用户 ID 覆盖添加到场所 up 20140617024603 添加隐身用户 up 20150107184219 屏蔽用户
heroku 的输出运行 rake db:migrate -
database: dfvpbkpnbntg2f
状态迁移 ID 迁移名称
up 20140423191412 创建用户 向上 20140423191450 创建联系人 up 20140423191657 创建场地 up 20140423191730 创建城市 up 20140423194439 建立友谊 up 20140423212732 创建邀请 up 20140423212915 添加默认邀请状态 向上 20140423213804 创建 kptwilios up 20140423221018 创建推送通知 up 20140423221315 创建设备令牌 up 20140423221356 添加默认到设备令牌环境 up 20140423225205 创建延迟的工作 up 20140430001800 添加用户ID到场所 up 20140430001824 添加json信息到场地 up 20140616234552 添加api id到场地 up 20140617012705 将用户 ID 覆盖添加到场所 up 20140617024603 添加隐身用户 up 20150107184219 屏蔽用户
我尝试将我的 database.yml 文件从 cityrails_production 更改为 dfvpbkpnbntg2f,但没有成功。
【问题讨论】:
你的数据库是什么?这就是它爆炸的地方 开发/测试中的sqlite3和生产中的pg 【参考方案1】:我在您的堆栈跟踪中看到了 rpush-1.0.0。 1.0.0 已经很老了。请使用 2.2.0
【讨论】:
难以置信。这正是问题所在。谢谢。【参考方案2】:database configuration does not specify adapter
表示config/database.yml
文件没有正确设置。请参阅http://guides.rubyonrails.org/configuring.html#configuring-a-database 了解有关该文件中应包含的内容的详细信息。
具体来说,错误信息指向找不到adapter: <database type>
https://gist.github.com/erichurst/961978 有一些database.yml
的示例,您可以在设置它们时参考。
【讨论】:
我已经用 database.yml 文件编辑了我的问题。 运行rake db:migrate:status
的输出是什么?
我看到您现在已将输出包含在问题中。诡异的。 rake db:migrate:status
能够正确使用数据库配置。运行 rpush init
时是否仍然出现错误?
是的,我仍然收到相同的数据库配置未指定适配器消息。
忽略我之前的评论 :-)以上是关于使用 Rpush 将推送通知添加到我的 rails 3 应用程序时出错的主要内容,如果未能解决你的问题,请参考以下文章
带有 Rpush gem 的 IOS/SWIFT 推送通知:生产中的无效令牌 (8)
使用 Rails RPUSH gem 为 APNS 编码 JWT 密钥