This is a blog of AmberBit - a Elixir and Ruby web development company. Hire us for your project!

Building small sites with LocomotiveCMS and deploying to Heroku and GridFS


Posted by Hubert Łępicki

Hubert is partner at AmberBit. Rails, Elixir and functional programming are his areas of expertise.
@hubertlepicki @hubertlepicki

So you have a small site to build and host cheaply. Let’s user Rails. Let’s deploy to Heroku. Let’s build around Locomotive CMS. Let’s see how.

LocomotiveCMS is lightweight CMS solution built on Rails and MongoDB. To be fair, I have love-me-hate-me relationship with MongoDB, but it definitely suits great for storing records with dynamic/not specified schema. This is perfect for CMS systems, where you want to define types of records as you go.

LocomotiveCMS documentation says you have to use Amazon S3. But you have limited budget or simply don’t want to include external dependency. As Locomotive CMS is already using Carrierwave and Mongoid, it should be possible to store uploaded files in MongoDB’s GridFS, right?

First, follow the excellent guide at Locomotive CMS site to get your site running on Heroku:

You can choose to use MongoLab or MongoHQ, I opted in for MongoLab, so I had to install their addon and replace MONGOHQ_URL with MONGOLAB_URL in documentation above, but that was all.

To actualy store files in GridFS instead of S3, you’ll have to modify you config/initializers/carrierwave.rb to include: = :grid_fs
config.grid_fs_connection = Mongoid.database
config.grid_fs_access_url = "/uploads"

That will make all assets and template files to be uploaded in GridFS. However, there is additional step to serve those. You need rack middleware to send out uploaded files, when user requests them: Add to your Gemfile:

gem 'rack-gridfs', :require => 'rack/gridfs'

run “bundle install”, and modify your config/application.rb with the following:

require 'uri'
uri = URI.parse(ENV['MONGOLAB_URI'])
config.middleware.insert_after Rack::Runtime, Rack::GridFS,
 :prefix => 'uploads', :lookup => :path,
 :database => uri.path[1..-1], :hostname => uri.hostname,
 :port => uri.port, :username => uri.user, :password => uri.password

Push to Heroku and voilà!


Hi there!

I hope you enjoyed the blog post. Can we help you with Elixir or Ruby work? We are looking for new opportunities at the very moment, and we do have team available just for you.

Email me at: or use the contact form below.

Want to get in touch about a project? Drop us a line!

When submitting the form, you are sending your personal information (including your name and e-mail as entered above) to AmberBit Sp. z o. o. is the receiving party, and a data controller, and will use the information you provided for the purpose of establishing relationship leading to possibly signing a services contract, and fulfillment of such contract only. We will not subscribe you to marketing lists, newsletters etc. You can read more about it in our Privacy Policy.