Reputation: 302
I am using the geoip gem in my rails app and I need to access the geoip.dat file, to get the ip data.
GeoIP.new("geoip.dat")
On my local environment I can access this file from anywhere, but when I put it on Heroku I just cant get it working. I always get the error that the file does not exist. I tried to put it in the root, /public, /lib/assets.
What am I doing wrong?
Thanks.
Upvotes: 2
Views: 1075
Reputation: 6138
If the file is in your public directory you can access it on Heroku. Make sure the file is in public/geoip.dat
and ensure that it is committed and pushed to Heroku. If you are developing locally on a Mac and pushing to Heroku, make sure you have the case of the filename exact. The case will be ignored on the Mac but will matter on Heroku.
You should be able to load the file with:
GeoIP.new(Rails.root + 'public/geoip.dat')
You can test this on heroku:
> heroku run console
Running `console` attached to terminal... up, run.3472
Loading production environment (Rails 4.0.0)
irb> File.exists?(Rails.root + 'public/geoip.dat')
=> true
irb> GeoIP.new(Rails.root + 'public/geoip.dat')
=> #<GeoIP:0x007f05a0215230 @mutex=#<Mutex:0x007f05a0215258>, @flags=0, @database_type=1, @record_length=3, @file=#<File:/app/public/geoip.dat>, @database_segments=[16776960]>
Upvotes: 2