Code Live: Railsbricks App

Shaun D
Fear and Coding
Published in
5 min readDec 8, 2014

--

Building Rails apps even faster

Monday 8th December — 1:11am

Railsbricks is an app generator for getting off to a flying start with a rails application. Now I already love the workflow for Rails, I think that it’s one of the more matured workflows for web application development that exists. Say what you want about Rails as a framework or Ruby as a language, it makes me feel productive and that makes me a happier developer.

On a daily basis I don’t get to work much with Ruby or Rails for that matter, but in my own time I have built a few applications using Rails and really enjoy using the framework and the tools around it. I already think that the standard Rails workflow is awesome and allows me to move fast with ideas, but Railsbricks takes care of a lot of general boilerplate stuff that you might do on most apps. It goes ahead and adds Bootstrap for UI, Devise for User Authentication, Layouts for headers and footers, Secret values for config stuff, email setup, contact forms etc etc. There’s a whole lot of options for it.

So, whilst I’ve now run out of Newsroom episodes, and Reddit seems to be having load issues

I thought to myself “Maybe I’ll download that Elvis movie where Kurt Russell plays Elvis”. Turns out there’s only like 5 seeds for the film so thats gonna take a while.

So, whilst I wait to get my Elvis on, I might as well get this device library thing up and running again.

What device library thing?

Well at NiceAgency (my current employer) I had built this small CRUD app that allowed the test devices to be tracked. It was originally built using Meteor and deployed on Heroku, but some idiot (me) dropped the MongoDB that it was using and rendered it useless. Now, I could have very well just brought it back up with a fresh DB — I had no backup — but I also wanted to add a couple of features to it, make it a bit less … prototypy (It was built in about 3 hours) and also put in some sort of backup routine. I could do all this in Meteor, but I wanted an excuse to use Rails and try out Railsbricks, so I chose to update it.

The device library just has the ability to add devices, edit them, assign them to a user and thats about it really. Its real simple way of tracking whom has what.

1:20am

I start out by installing Railsbricks, easily done by following their guide, tis just a simple gem install. I use RVM as my Ruby version manager. I know a lot of people prefer rbenv, but I’ve always used RVM and never really had any problems with it. I know that Railsbricks uses Ruby 2.1.5 so I go ahead and rmv install that version and im good to go.

I then kick off with the rbricks commands.

After about 45 seconds of questions to set up your app, all of which are easy to answer even if you’ve never really written a rails application before, Railsbricks goes off and starts creating the boilerplate for your app.

It goes off and sets up a Unicorn config for production (Unicorn is a HTTP server for Rack applications), sets up some dummy users, routes, paths, models and views. Sets up a default admin user and some templates to get going.

I cd into my app folder and run rails s and badaboom ….

Love it. That really is fast.

I open the project up in Sublime and it looks like a regular rails project, just with tons of stuff already set up.

1:35am

Had a play around for a couple of minutes, editing users, changing passwords etc — all works as expected. I now realise that maybe adding the ability to add posts isn’t quiet what I need, so going to have to change that.

So from here on in Railsbricks is kind of done, its back to straight-up Rails development, but its saved a lot of time getting our boilerplate app set up.

1:50am

Used rails scaffolding to scaffold out the device stuff.

Im really just going by what I used before in the meteor app. I then run a db:migrate to create the database table.

Whilst adding some seeds to the DB seed file I realise that I should have set the available field to a boolean, oh well I can change that when I need too.

I set up some dummy data in the seeds file for creating some devices by passing an array to the create method.

2:25am

Whoopsie, I used the field type for device and thats a reserved word so I got a fail when trying run my seeds. Im sure that best practices dictate say that you should just run another migration to fix the field in the schema, but all I did was just edit the Device migration file to have a device_type field and then run rake db:drop db:create db:migrate then I can run rake db:seed and get everything I need.

Sweet!

Needs a bit of style work, but all is good in the hood. Elvis has now finished downloading so I’m going to indulge in that now. I’ll come back to this tomorrow.

--

--

Shaun D
Fear and Coding

💻 Freelance creative tech. 🚀 Rocket Man.🥋BJJ White Belt Noob.