Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vanity, Rails 3 and Heroku

I'm trying to get Vanity to play nicely with Heroku and my Rails 3 app. At the moment, it all works fine locally using Pow and a local Redis server, but when I push to Heroku using the RedisToGo add-on, nothing seems to get the server running, I just get the error: getaddrinfo: Name or service not known.

Here's my config/vanity.yml file:

staging:
  adapter: redis
  host: <%= ENV["REDISTOGO_URL"] %> 

and my config/initializers/redis.rb:

uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

I've also tried using the actual redis://<actualusername>:[email protected]:9274 and it gives the same error. I've also tried with and without the redis://.

Has anyone got Vanity working with Heroku and Rails 3? Am I missing something terribly obvious? My Google-fu has failed me thus far.

like image 347
Tim Sullivan Avatar asked Jun 12 '11 04:06

Tim Sullivan


3 Answers

Yeah, it was something stupid, all right. You don't use host, you use connection.

staging:
  adapter: redis
  connection: <%= ENV["REDISTOGO_URL"] %> 

Hope this helps someone, because I nearly beat my computer to a pulp.

like image 197
Tim Sullivan Avatar answered Nov 15 '22 17:11

Tim Sullivan


If you are using Postgres on Heroku you need to do things a bit different. Here is my hack (config/vanity.yml):

production:
  adapter: active_record
  active_record_adapter: postgresql

  <% username, password, host, database = ENV['DATABASE_URL'].scan(%r{//(.*):(.*)@(.*)/(.*)}).first %>
  host:     <%= host %>
  username: <%= username %>
  password: <%= password %>
  database: <%= database %>

And you have to force Vanity to not use the Redis adapter (a bug if you ask me). Put this in an initializer:

Vanity.playground.establish_connection(Rails.env.to_sym)
like image 26
Jeroen van Dijk Avatar answered Nov 15 '22 17:11

Jeroen van Dijk


One final note: If you're using ActiveRecord & Postgres on Heroku and you ARE NOT on the shared database, the connection string should be:

username, password, host, port, database = ENV['DATABASE_URL'].scan(%r{//(.*):(.*)@(.*):(.*)/(.*)}).first
like image 40
earnold Avatar answered Nov 15 '22 15:11

earnold