Let’s say you want to deploy RhoConnect on Heroku but don’t want to use RhoMobile’s official RhoConnect addon (docs here and here). This would mean that you’d have to use the Redis To Go addon or get your own redis instance up and running on AWS.
The easiest way to go about this is to use Redis To Go (RTG), but there is one tweak you have to make to get it talking with RhoConnect.
Add the following lines to the Application.initializer method in application.rb, before the super call:
classApplication<Rhoconnect::Baseclass<<selfdefauthenticate(username,password,session)true# do some interesting authentication here...end# Add hooks for application startup here# Don't forget to call super at the end!definitializer(path)ifENV['REDISTOGO_URL']uri=URI.parse(ENV["REDISTOGO_URL"])Store.db=Redis.new(:host=>uri.host,:port=>uri.port,:password=>uri.password)endsuperend# Calling super here returns rack tempfile path:# i.e. /var/folders/J4/J4wGJ-r6H7S313GEZ-Xx5E+++TI# Note: This tempfile is removed when server stops or crashes...# See http://rack.rubyforge.org/doc/Multipart.html for more info# # Override this by creating a copy of the file somewhere# and returning the path to that file (then don't call super!):# i.e. /mnt/myimages/soccer.pngdefstore_blob(object,field_name,blob)super#=> returns blob[:tempfile]endendendApplication.initializer(ROOT_PATH)# Support passenger smart spawning/fork mode:ifdefined?(PhusionPassenger)PhusionPassenger.on_event(:starting_worker_process)do|forked|ifforked# We're in smart spawning mode.Store.db.client.reconnectelse# We're in conservative spawning mode. We don't need to do anything.endendend
To explain this a bit, if you install the RTG addon, it adds an REDISTOGO_URL environment variable to your heroku instance, with a value like this:
It’s relatively straightforward to configure RhoConnect for a single environment (i.e. production), but things get more complicated if you want to have a robust way to deploy to several environments (i.e. development, testing, production).
In this post I’ll show you how to do the following:
Set up global and environment-specific configurations
Configure RhoConnect to use a given environment’s settings