The uservoice gem provides a nice easy way to integrate your Rails app with the UserVoice user feedback service. If you’re using Heroku to deploy your Rails app, there are two things that will provide speed bumps. The first is that, short of storing your UserVoice API key in your git repository, there’s no way to get it into your Rails app’s configuration. The second is that the uservoice gem lists rails as a dependency. Both can be overcome, and I’ll describe how.
Securely Passing Your UserVoice API Key To Heroku
In order to pass your UserVoice API key to Heroku without committing it in plain-text in your git repository we make use of Heroku’s config feature.
$ heroku config:add USERVOICE_API_KEY=<your api key> USERVOICE_USER=<your username>
This will make your UserVoice API Key and username accessible to your Heroku Rails app via ENV["USERVOICE_API_KEY"] and ENV["USERVOICE_USER"] respectively.
Now we simply need to get these values into the uservoice gem’s config/uservoice.yml configuration file. To do this,
we need to add ERB support to the uservoice gem’s config loader
Now we can setup our uservoice gem configuration file like so:
key: <%= ENV["USERVOICE_USER"] %>
api_key: <%= ENV["USERVOICE_API_KEY"] %>
Installing The Uservoice Gem To Heroku
Of course we need to add the uservoice gem to our .gems file. However, the uservoice gem lists Rails as a dependency. This means that when Heroku installs the uservoice gem, it will also install the latest version of Rails (2.3.8 at the time of writing). Heroku’s stack currently relies on Rails version 2.3.5, and having the two versions of Rails installed causes a clash. The solution is to add the --ignore-dependencies flag to the uservoice line of the .gems file. However, this means that Heroku won’t install uservoice’s other dependency, the ezcrypto gem. To work around that, we simply add ezcrypto manually, on it’s own line, to the .gems file. The lines that need to be added should look like this:
ezcrypto --version '>= 0.7.2'
uservoice --version '>= 0.3.1' --ignore-dependencies
While the version arguments aren’t strictly necessary, I’ve found it helpful to be explicit when specifying gems, to help alleviate issues caused by new versions of gems being released in the middle of my development cycle.
With those changes in place, you should be able to push your git repository to Heroku and receive all sorts of great user feedback.