I can launch a basic app on Heroku, displaying a message with get '/'... works just fine. However, whenever I try to add sqlite with datamapper, the thing breaks down.
In order to see my app structure, check out the project on github. I've kept the code pretty bare-bones.
In the log from heroku I'm getting:
2011-06-26T21:28:36+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/adapters.rb:163:in `require': no such file to load -- dm-postgres-adapter (LoadError)
The thing about this is that I'm not using postgres, so I'm confused why it is saying this.
"The thing about this is that I'm not using postgres, so I'm confused why it is saying this."
You're using Heroku, so you are using Postgresql.
In your app.rb you have this line:
DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/notes.db")
which I'm guessing you got from the Heroku database docs. This line basically says "check for the environment variable 'DATABASE_URL', and if it's set use it as the database url, otherwise use the Sqlite url". Running locally this environment variable won't be set, so you'll use the Sqlite url, but on Heroku this will be set to something like (see the page linked above):
postgres://username:password#hostname/database
Datamapper will see that this is a Postgresql url, and try to require the postgres adapter, which isn't installed so will result in the error that you see.
The best solution would be to install Postgresql locally, so that your development and production environments are as similar as possible. If you can't do this, or don't want to, you can specify the Sqlite adapter locally, and the Postgres adapter in production. It'll look something like this in your Gemfile:
group :development do
gem 'dm-sqlite-adapter'
end
group :production do
gem 'dm-postgres-adapter'
end
If you do this you'll need to tell Heroku to which groups to leave out when installing gems, see the Heroku Gem Bunder docs.
You are moving from sqlite to postgres-sql and thus you should include dm-postgres-adapter in your Gemfile (and install it ofcourse).
Heroku only supports a read-only file system (or at least only supports read-only operations for any files that you want to be persistent). Hence, you can't use SQLite on Heroku. Heroku only supports PostgreSQL as a database so you need to configure DataMapper to use PostgreSQL (see Yet Another Geek's answer).
I'd recommend installing PostgreSQL in your development environment if you're planning to deploy to Heroku. Every database is a little different and no ORM will protect you from the differences. A bit of searching for questions tagged heroku and postgresql should show some of the problems you'll have if you develop on top of one database but deploy on another.
Related
I am working on a gem that needs to be configured with a hostname, username, and password. I would prefer to store this configuration information in config/directoryservices.yml
How do I make my gem automatically create this file when installed?
I've seen a lot of places say that config information should be passed as hashes with gems. The main use of this gem will be in an app that is installed on ~15 servers. Each server will need different config information.
If it is better to include the YAML code in the app and then pass the data as a hash to the gem, I can do that, but I would still like pointers on the best way to do that.
An example of a gem that uses this kind of config is activeldap
If are you working on rails gem, you can create install generator which will copy default config file and then load it into your app.
I have been struggling for the last couple hours with this question, and I hope someone can help me out. I'm creating my first Sinatra app and I would like to use Mongo as the backend. I have decided to use Heroku's MongoLab service, and it gave me a connection URI to use to connect with Mongo from within my Sinatra app. This does not seem like the type of info I want to keep in Version Control, but I'm having a hard time figuring out how to not hardcode it into the application. On one hand the key is stored permanently as a Heroku ENV var, but that does not help when I'm developing locally. I've tried creating a config file as outlined here: http://www.miqueloliete.com/configuring-environment-variables-in-sinatra/, but it only helps locally. I can't seem to find the way to do this.
Thanks in advance,
Ryan
There are many ways to achieve these so I can just give you ideas.
Env
You can set the enviroment variable on your local pc with export name=mongourl
configuration
Sinatra provide a way to use different configuration sections. That is what I do normaly. Like these:
configuration :development do
setup things to use your local db
end
configuration :production do
setup things for production db
end
config file
Store these informations in a yaml file.
I figured out the best way to do it for me. I didn't realize that in Ruby ENV['somevar'] accessed your environmental variables for your shell, so in order to not commit my secret keys and passwords to version control, I just make sure that all my environmental variables that I had in my Heroku (the results of heroku config) were also variables in my shell.
You can use the dotenv gem and then create a .env file locally that has the same keys as your Heroku ENV variables. That way you can keep the same environment keys in your code for both environments, and choose to have identical or different values, as needed.
#app.rb
require 'sinatra/base'
...
if Sinatra::Base.environment == :development
require 'dotenv'
Dotenv.load
end
#.env
DATABASE_URL=mongo_sinatra_connection_info
I have a Rails app running on heroku. Now I want to run a rake task (which uses a model of my rails app) and geo-tag each record using the MaxMind GeoIP database (http://www.maxmind.com/app/geolite).
Using this database in a Ruby application involves :
Building it's C-API (http://www.maxmind.com/app/c) and then
Build the Ruby bindings for that (http://www.maxmind.com/app/ruby).
I could do this on my local machine and successfully get the country codes from IP addresses. However I do not know how to install these libraries on Heroku. From what I understand the ruby bindings are not available as a gem with native extensions (which heroku would have handled just fine). Also their C-API seems to have a few other dependencies which makes me wonder whether such a thing is possible at all.
So has anyone installed the MaxMind GeoIP (a.k.a Net::GeoIP) on Heroku? If yes how?
I could run the rake task from my laptop by pointing my local setup to the production DB. Before that I would like to know if I can run it from my Heroku setup itself to avoid latency or connection breakdown etc.
I found a gem which bundles the MaxMind C-API and provides it's own Ruby API. It works just fine - http://rubygems.org/gems/geoip
I ll tentatively accept this as the answer. However it would be awesome if someone can tell me how to install binary extensions to Ruby on Heroku.
I've had some problems running an app on Heroku. It uses Sinatra and Datamapper. The full project is here: https://github.com/pixelwolf/phonedb
The problem happens when I deploy the app, all goes well, until I go to the url, where I get an "Application Error" page. I have also push the SQLite3 database using heroku db:push sqlite://database.db
Here are the logs from running heroku logs: https://gist.github.com/1439777
You have to configure your database in datamapper with a line like this
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'sqlite3://my.db')
That was from heroku's website. http://devcenter.heroku.com/articles/database That will configure datamapper to continue to allow you to use sqlite3 on your local machine but switches to Heroku's postgres DB when the application is used there.
Also, Tom Anderson is correct, you need to add the dm-postgres-adapter gem to your Gemfile. I also added the pg gem as well, I'm not sure if that was necessary though.
The error page has the line:
`require': no such file to load -- dm-postgres-adapter
You can only use postgres on heroku. So likely you are not accounting for that in some way. You can develop with sqlite on your machine, but you then need to arrange a few things to make it all work, plus you need to not use any sqlite or postgres only features.
Adapters not working with datamapper
Heroku and Datamapper problems
http://www.ruby-forum.com/topic/1770484
I’m trying to setup a Heroku app but using a Xeround DB. The instructions I have found are a bit confusing:
http://xeround.com/developers/heroku-cloud-database-mysql/
I'm trying to follow the second way, creating the db directly on Xeround.
My doubts are:
Is the Xeround addon required for this? At least heroku addons:add xeround –app xxxx says: That add-on is only available to selected users
The Heroku DATABASE_URL needs to be set to: mysql://username:password#host:port/database
I've seen some posts with mysql2 and mysql (none has worked for me anyway). My gem file has mysql2, 0.2.7 (for Rails 3.0.x)
I can see the config var ok, but Heroku config --app xxx still shows SHARED_DATABASE_URL => postgres://pjyqfgjcbn:.... is that ok?
Then from the instructions the step #5 is really confusing, it is not clear if that part is optional or not (I expect it is). And if it was mandatory it doesn't tell to which file it has to be added ...
My objective is to create a fresh Heroku app, push an existing app I have, set it up to use the Xeround DB and then run Heroku rake db:schema:load but no matter what I try I keep getting:
rake aborted!
database configuration does not specify adapter
Any ideas how to set it up?
do the same with Rails 3.0.5 but having some problems and comments.
Is the adapter mysql or mysql2? The example on Xeround about the setup site is mysql://username:password#host:port/database
mysql2 is correct gem to use with Rails 3 (mysql 0.2.7 for 3.0.x and latest for 3.1) but the name in the url might be just a name they picked. I guess yours worked but still…
I imagine the Xeround addon of Heroku is not needed right?
heroku addons:add xeround –app xxxx says That add-on is only available to selected users
And finally with mysql or mysql2 in the name of the db url when I try to migrate I just get:
rake aborted!
database configuration does not specify adapter
Did ask Heroku but no answer yet…
I've been using Xeround for several of my apps hosted on Heroku.
I don't have specific experience with Rails. Sinatra only... But hopefully this helps you out.
I do not use the add-on. It's less expensive to setup an account through Xeround on your own.
Connect to it just like you would any MySQL Database....
Connection String will look just like you stated:
mysql://username:password#host:port/database
Host/Port are provided by Xeround in the admin database. Database name would be whatever you setup in phpMyAdmin. User/pass are NOT your Xeround account credentials. They are the credentials you setup for that database instance.
For example... if your ORM is Datamapper... do something like this:
DataMapper.setup(:default, ENV['XEROUND_CONN'])
Or if you're using Sequel:
DB = Sequel.connect(ENV['XEROUND_CONN'])
Then you need to set your XEROUND_CONN (or whatever you wish to call it) ENV variable.
Do this by using the Heroku command
heroku config:add XEROUND_CONN='mysql://username:password#host:port/database'
Warning: Datamapper has an issue with Xeround. Datamapper does not have support for setting your storage engine (myisam..etc..). Xeround uses their own custom Xeround storage engine. So... I've had trouble running auto_migrate due to differences in storage engine.