Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninitialized constant APN::App::RAILS_ENV #53

Open
azcoov opened this issue Jul 17, 2012 · 13 comments
Open

uninitialized constant APN::App::RAILS_ENV #53

azcoov opened this issue Jul 17, 2012 · 13 comments

Comments

@azcoov
Copy link

azcoov commented Jul 17, 2012

Hi there, Rails noob here and I'm struggling trying to figure out how to solve this error. It's barking about the RAILS_ENV variable. I've tried a couple of forks that change this to Rails.env but I still get the same error. I don't know enough about rails to dig in any further and I was hoping you could point me in the right direction.

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
@kookster
Copy link
Member

Are you using bundler?

Are you running it as bundle exec rake?

Andrew Kuklewicz

On Tue, Jul 17, 2012 at 5:11 PM, Billy Coover <
reply@reply.github.com

wrote:

Hi there, Rails noob here and I'm struggling trying to figure out how to
solve this error. It's barking about the RAILS_ENV variable. I've tried a
couple of forks that change this to Rails.env but I still get the same
error. I don't know enough about rails to dig in any further and I was
hoping you could point me in the right direction.

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


Reply to this email directly or view it on GitHub:
#53

@azcoov
Copy link
Author

azcoov commented Jul 17, 2012

Yes I'm using bundler.

I've tried running the following:

rake apn:notifications:deliver
and
bundle exec rake apn:notifications:deliver

Both fail with the same error.

@garyfoster
Copy link

I'm having the exact same issue and getting uninitialized constant APN::App::RAILS_ENV, I just started working on this today. Mine is a Rails 3.2 app, I'm simply adding gem 'apn_on_rails' to my gem file and normal bundle install.

If I do not use an APN::App model and rely on the configatron, I get the following error: No such file or directory - /config/apple_push_notification_development.pem. Configatron config is verbatim from the readme: configatron.apn.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_development.pem')

I'm having the feeling that maybe I'm not pulling from the correct repository and will investigate that next.

@garyfoster
Copy link

Oh well, I'm able to work around this by hardcoding the full path in app/models/apn/app.rb, line 35 of def self.send_notifications where it is assigning global_cert. I can now continue my testing but will be interested in the real solution so I can unpatch my code.

@garyfoster
Copy link

oh... to help azcoov, in order for my hack to work I first had to put the following line at the top of configatron/development.rb:

RAILS_ROOT, APN::App::RAILS_ENV='development'

I found this in another open issue on this site.

@azcoov
Copy link
Author

azcoov commented Jul 18, 2012

Thanks Gary! I'll give this a whirl.

// Billy

On Wednesday, July 18, 2012 at 7:14 AM, garyfoster wrote:

oh... to help azcoov, in order for my hack to work I first had to put the following line at the top of configatron/development.rb:

RAILS_ROOT, APN::App::RAILS_ENV='development'

I found this in another open issue on this site.


Reply to this email directly or view it on GitHub:
#53 (comment)

@azcoov
Copy link
Author

azcoov commented Jul 18, 2012

@garyfoster What's that hard-coded path look like for you after the change?

global_cert = File.read(RAILS_ROOT/config/apple_push_notification_development.pem) or is it something different?

@garyfoster
Copy link

global_cert = File.read("/Users/garyfoster/Documents/Projects/ruac/config/apple_push_notification_development.pem")

I've since found that my configatron settings are not being read so it's falling back to the defaults. I'm sure I can figure this out properly but i've got my head in my ios client side code and need to focus on that so I'm only giving it a half-ass effort.

@nstanev
Copy link

nstanev commented Jul 25, 2012

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 user Rails 3.1.0 and I do NOT have RAILS_ROOT/ENV/blah there. Instead, I have Rails.root/env/blah. When I replace RAILS_ENV with Rails.env in app/models/apn/app.rb the first problem goes away. Then I get the second error: "No such file or directory - /config/apple_push_notification_development.pem", which could be because ROOT_ENV is non-existant. (Although I don't have ANY configatron stuff in my config files - not sure whether that's an issue if I store the certs in the DB).

So, the bottom line is, is this gem compatible with Rails 3.1.0??? It seems not. Is there a workaround that wil allow its use in a Production environment? Maybe similar to one of the above suggestions: define somewhere APN::App::RAILS_ENV = Rails.env. But where?

@garyfoster
Copy link

I lost interest in this problem when I realized I do not need this functionality to go live unless I use the supplied rake task. Here is what I did to proceed:

  1. add a record to the APN::App model and updating apn_prod_cert and apn_dev_cert with the contents of your cert pem files appropriately
  2. use APN::App.send_notifications, this bypasses the seemingly faulty configatron settings to get the certs since they are stored in the database

For #2, I ended up creating my own rake task since I needed it to do some other things as well. The task get's the appropriate APN::App and executes it's send_notifications method. If you have just one app, you could do something like the following:

app = APN::App.first
app.send_notifications

@nstanev
Copy link

nstanev commented Jul 25, 2012

@garyfoster Thanks for the tips! I actually did get this to work yesterday by doing the same: add the certs to the APN::App table and create my own rake task that uses APN::App.send_notifications directly. :)

HOWEVER, that method still calls APN::App.cert, which does '(RAILS_ENV == 'production' ? apn_prod_cert : apn_dev_cert)'. I had to put 'APN::App::RAILS_ENV = Rails.env' at the top of my config/environment.rb file. Did you have to do anything similar to bypass the deprecated env variable?

@garyfoster
Copy link

ah, yes, I did that same thing as well, had forgotten

@Nuttapon
Copy link

 I am beginner ruby on rails and weak english language. I use Rails 3.2.8

Yeah !! I can push notification.

  1. Gemfile >> i use gem 'apn_on_rails' then bundle install this version 'apn_on_rails' >> 0.5.1
  2. In configatron/development.rb >> i add line "RAILS_ROOT,APN::App::RAILS_ENV = Rails.env"
  3. so content in configatron/devlopment.rb below

eg. in file configatron/devlopment.rb

   RAILS_ROOT,APN::App::RAILS_ENV = Rails.env
   configatron.apn.passphrase  = '1150'
   configatron.apn.port  = 2195
   configatron.apn.host  = 'gateway.sandbox.push.apple.com'
   configatron.apn.cert = File.join(RAILS_ROOT, 'config', 'apple_push_notification_development.pem')

   configatron.apn.feedback.passphrase  = '1150'
   configatron.apn.feedback.port  = 2196
   configatron.apn.feedback.host  = 'feedback.sandbox.push.apple.com'
   configatron.apn.feedback.cert = File.join(RAILS_ROOT, 'config', 'apple_push_notification_development.pem')

I run "rails c" for create App, Device and Notification
but I can't use APN::APP.create so I use APN::APP.new instead and I have file "apple_push_notification_development.pem" in config

eg.

 app = APN::APP.new   
 app.apn_dev_cert = Rails.root.join('config', 'apple_push_notification_development.pem').read
 app.apn_prod_cert = Rails.root.join('config', 'apple_push_notification_production.pem').read
 app.save!

eg.

 device = APN::Device.new  
 device.token = "your device token" >>  "asdfghjk qwsafdewq qqwesaer ......"
 device.app_id = "1"
 device.save!

eg.

 notificaiton = APN::Notification.new
 notificaiton.device_id = "1"
 notificaiton.sound = "1.aiff"
 notifcaiton.alert = "I love ruby on rails"
 notifcation.badge = "1"
 notifcation.save!

I create my task in lib/tasks so i create file apn_on_rails.rake

eg.

 task :deliver_notifications => [:environment] do
      APN::App.first.send_notifications
 end

so in rails console >> rake deliver_notifications

It work for me. I can deploy on Heroku

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants