7

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>:actualpassword@actualserver.com: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.

phillbaker
  • 1,518
  • 11
  • 22
Tim Sullivan
  • 16,808
  • 11
  • 74
  • 120

3 Answers3

9

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.

Tim Sullivan
  • 16,808
  • 11
  • 74
  • 120
4

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)
Jeroen van Dijk
  • 1,029
  • 10
  • 16
  • 1
    Do you know if Vanity uses its own connection pool to the database? If so, I have a feeling it will have contention with the app over the limited number of connections that Heroku provides. – Chloe Mar 14 '14 at 05:34
3

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
earnold
  • 1,440
  • 1
  • 15
  • 26
  • I did something like a u = Uri.parse(ENV['DATABASE_URL']); username = u.user just to be more straightforward. – owyongsk Apr 14 '15 at 10:44