Vanity, Rails 3 and Heroku

冷暖自知 提交于 2019-12-22 04:59:09

问题


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.


回答1:


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.




回答2:


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)



回答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


来源:https://stackoverflow.com/questions/6320179/vanity-rails-3-and-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!