Some of my rSpec tests are failing and I suspect it's due to the test database not being cleared out. When I try to run rake db:test:prepare, I'm getting the error below (i'm in Rails 3.2). Clearly, this looks like some kind of Postgres issue, looks like the rake task is trying to drop the test database so it can repopulate it. Production database schema loads fine.
I've looked for the rake task in lib/tasks/ but I haven't been able to find it. Anyone have any idea on what's going on?
osx_user-> rake db:test:prepare
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
rake aborted!
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: DROP DATABASE IF EXISTS ""
^
: DROP DATABASE IF EXISTS ""
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `async_exec'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-3.2.14/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:623:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:532:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:559:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `eval'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
Figured it out. My database.yml file for the development environment was set like this:
database: <%= ENV['DATABASE_NAME_TEST'] %>
The rake task was looking for an environmental variable that did not exist.
Related
i have a rake task as follows-
desc 'send fetch request'
task send_fetch_request: :environment do
FacebookCrawl.new.process
end
Yesterday this task working, but I don't know why it is not working today.
I am trying to execute this with the below command-
rake send_fetch_request
Class details:
class FacebookCrawl
def initialize
fb_config = YAML.load_file(Rails.root.join("config/facebook_catalog.yml"))
#access_token = fb_config["facebook"]["access_token"]
#product_feed_ids = fb_config["facebook"]["product_feed_ids"]
end
def process
#product_feed_ids.each do |key,value|
feed_id = value["id"]
feed_url = value["feed_url"]
make_request(feed_id,feed_url,#access_token)
end
end
end
I am getting below error:
rake send_fetch_request --trace
** Invoke send_fetch_request (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute send_fetch_request
rake aborted!
NameError: undefined local variable or method ` FacebookCrawl' for main:Object
/Users/raj.sharma/Documents/Developer/Feed/lib/tasks/facebook_fetch_request_task.rake:3:in `block in <top (required)>'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `call'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/Users/raj.sharma/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/Users/raj.sharma/.rbenv/versions/2.2.2/bin/rake:22:in `load'
/Users/raj.sharma/.rbenv/versions/2.2.2/bin/rake:22:in `<main>'
Tasks: TOP => send_fetch_request
Yesterday it was working fine, I don't why rake is complaining today. Please help.
Please, look carefully at the error message:
NameError: undefined local variable or method ` FacebookCrawl' for main:Object
# ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑
The first giveaway is that you get a NameError for an undefined local variable or method, and not for a constant. The second giveaway is the name that Ruby complains about: it doesn't complain about FacebookCrawl, it complains about FacebookCrawl.
In Ruby, only the Unicode characters U+0020 SPACE and U+0009 CHARACTER TABULATION are treated as whitespace. You have two Chinese U+3000 IDEOGRAPHIC SPACE characters, which Ruby simply treats as part of the name, and since they are not uppercase characters, it treats the name as a local variable or message send.
You should probably turn on visible whitespace in your editor, e.g. this is how your code looks in my editor, making it immediately obvious where the problem is:
Copy the facebook_crawl.rb in app/services folder & restart the server.
This is your business logic, so it should be in services folder & not in the models
So create a services folder as well in the app directory.
I'm a beginning rails student at OneMonth learning stripe payments. Right now, I'm learning how to create a product table and seed the database. Everything's been smooth so far until I encountered a problem after running rake db: seed
Davids-MBP-2:one_month_stripe_payments DKP$ rake db:seed
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Email has already been taken
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/validations.rb:79:in raise_record_invalid'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/validations.rb:43:insave!'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/attribute_methods/dirty.rb:29:in save!'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/transactions.rb:291:inblock in save!'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/transactions.rb:351:in block in with_transaction_returning_status'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:inblock in transaction'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in within_new_transaction'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:intransaction'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in transaction'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/transactions.rb:348:inwith_transaction_returning_status'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/transactions.rb:291:in save!'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/persistence.rb:51:increate!'
/Users/DKP/Desktop/one_month/one_month_stripe_payments/db/seeds.rb:8:in <top (required)>'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:inload'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in block in load'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:inload_dependency'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in load'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/railties-4.2.5/lib/rails/engine.rb:547:inload_seed'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:250:in load_seed'
/Users/DKP/.rvm/gems/ruby-2.3.0#global/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:183:inblock (2 levels) in '
/Users/DKP/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in eval'
/Users/DKP/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
I've tried rake db: reset, then rake:db migrate, then rake db: seed again. But i still have the same error.
Could anyone help me with this problem please? I'm feeling stuck and I'm not sure what to do.
Thanks so much!
When you do rake db:reset, what rails does is rake db:drop -> rake db:create -> rake db:migrate -> rake db:seed.
You DO NOT need to rake db:seed again.
you can check your console by doing rails c and see if you seed data is already inside. Product.all
'Email has already been taken' means you have a record with the same email already present.
Do Rails console and check if the records are there or not.
If not, do rake db:drop -> rake db:create -> rake db:migrate -> rake db:seed. This will solve your problem.
I am a new ROR developer. We are developing an application using Rails and AngularJS. A brief background of what I was trying to do:
Another developer developed an application (partial) named hiredjob. I have to continue development with his application changing the name of the application to hiredtoday and also changing all the models from admin_X to X . For that following is the sequence of steps I follow:
Method 1:
Copy the old hiredjob application to a new application hiredtoday.
Delete all db/migrate.
rails generate devise admin.
rake db:migrate gives error
Error from rake db:migrate:
home/arshi/.rvm/gems/ruby-2.2.3/gems/devise-
3.5.2/lib/devise/rails/routes.rb:485:in `raise_no_devise_method_error!': Admin does not respond to 'devise' method. This usually means you haven't loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb' (RuntimeError)
On searching solution for above on the internet, I comment devise_for :admins in config/route.rb
After which on running rake db:migrate again I got an error.
Error is as follow:
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Table 'hiredjob_development.admins' doesn't exist: ALTER TABLE 'admins' ADD 'email' varchar(255) DEFAULT '' NOT NULL/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `query'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `block in execute'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activesupport-4.2.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:467:in `log'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `execute'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:231:in `execute'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:393:in `add_column'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:573:in `block (3 levels) in <class:Table>'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:572:in `each'
/home/arshi/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:572:in `block (2 levels) in <class:Table>'
Note: I have also tried to do run: rake db:drop db:create db:migrate. But still does not work.
i think you are getting this error because devise depends on the table already having been created. you need to:
1) delete the devise migration
2) write a migration to create the admins table http://guides.rubyonrails.org/active_record_migrations.html#creating-a-table
3) regenerate the devise migration.
I've got a model, say User, and a model Admin which inherits from User. I have some code in lib folder which uses those two models. But if I install a new database and try to run the migrations rails crashes saying that there is no such model as User. Are there any best practices to bypass this error?
`Mysql2::Error: Table 'testing_interface_development.users' doesn't exist: SHOW FULL FIELDS FROM `users`
/home/arthurborisow/Programming/my_project/test_interface/lib/active_record/timed_out_queries_hotfix.rb:9:in `query'
/home/arthurborisow/Programming/my_project/test_interface/lib/active_record/timed_out_queries_hotfix.rb:9:in `query_with_reconnect'
/home/arthurborisow/Programming/my_project/test_interface/lib/active_record/timed_out_queries_hotfix.rb:31:in `block in execute'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activesupport-3.2.11/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/home/arthurborisow/Programming/my_project/test_interface/lib/active_record/timed_out_queries_hotfix.rb:31:in `execute'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:259:in `execute_and_free'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:426:in `columns'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:228:in `yield'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:228:in `columns'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:237:in `columns_hash'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/inheritance.rb:19:in `descends_from_active_record?'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/inheritance.rb:25:in `finder_needs_type_condition?'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/base.rb:455:in `relation'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/scoping/named.rb:37:in `scoped'
/home/arthurborisow/.rvm/gems/ruby-1.9.3-p362-railsexpress#test_interface_install/gems/activerecord-3.2.11/lib/active_record/querying.rb:9:in `where'
/home/arthurborisow/Programming/my_project/test_interface/app/models/admin.rb:15:in `<class:Admin>'
/home/arthurborisow/Programming/my_project/test_interface/app/models/admin.rb:1:in `<top (required)>'`
When setting up a completely fresh database (instead of upgrading your existing one), it is better to use rake db:setup to load the schema.rb file instead of running each migration in succession. This question explains the various db Rake tasks pretty well:
Difference between rake db:migrate db:reset and db:schema:load
rake db:setup
Is the best option also,
You can also specify your migration version which do you want to migrate using below command:
rake db:migrate:up VERSION=20080906120000
I'm struggling with this error after I fire the command rake apn:notifications:deliver on the APN on Rails gem that I've installed.
It's barking about the RAILS_ENV variable. I've tried a couple of forks that change RAILS_ENV to Rails.env but I still get the same error. I've posted my issue over on that repo hoping I might get somewhere.
I don't know enough about rails to dig in any further. I'm hoping someone could point me in the right direction so that I can a) better understand what went wrong and b) fix the problem.
I am using bundler and I'm pointing my gem file to the git repo: rake apn:notifications:deliver
air:apnapp azcoov$ rake apn:notifications:deliver --trace
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/version.rb:2: warning: already initialized constant VERSION
** Invoke apn:notifications:deliver (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute apn:notifications:deliver
rake aborted!
uninitialized constant APN::App::RAILS_ENV
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:11:in `cert'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:22:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:32:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:31:in `each'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:31:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/rails/../tasks/apn.rake:7
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
Tasks: TOP => apn:notifications:deliver
Which version of Rails to you use? I just ran into this issue too. My Rails knowledge is not very deep, but it seems like the problem is deprecation of RAILS_* environment variables. I use Rails 3.1.0 and I do NOT have:
RAILS_ROOT/ENV/blah
in my environment. Instead, I have:
Rails.root/env/blah
When I replace RAILS_ENV with Rails.env in app/models/apn/app.rb the problem goes away.
So, is this gem compatible with Rails 3.1.0??? It seems not. Is there a workaround that will allow its use in a Production environment? Maybe define somewhere:
APN::App::RAILS_ENV = Rails.env
But where?
UPDATE:
I got it working with a workaround described by garyfoster here: https://github.com/PRX/apn_on_rails/issues/53.
To summarize, three things:
1) Add this ghetto hack to your config/environment.rb file:
APN::App::RAILS_ENV = Rails.env
2) Insert your certs in the APN::App table. I wrote a one-time rake task for that:
task :init_apn_certs => [:environment] do # NOTE: One-time task...
print "Creating APN::App with certs..."
app = APN::App.create(:apn_dev_cert => Rails.root.join('config', 'apple_push_notification_development.pem').read,
:apn_prod_cert => Rails.root.join('config', 'apple_push_notification_production.pem').read)
puts (app.valid? ? "done" : "failed")
end
3) Write your own rake task that bypasses the APN::App.send_notifications method, as that barfs with another error (something about '/config/apple_push_notification_development.pem' not existing). My code for it:
task :deliver_notifications => [:environment] do
print "Delivering APNs for app ids..."
apps = APN::App.all
apps.each do |app|
app.send_notifications
print app.id.to_s + "..."
end
puts "done."
end
Or, if you have only one app, you can just do this and be done with it:
task :deliver_notifications => [:environment] do
APN::App.first.send_notifications
end
DISCLAIMER: I'm yet to test this on Staging and Production (will do so by the end of the week), but I see no reason why it shouldn't work.