What’s the first thing you look at when you see the source code of a Rails project?

For me, it’s the Gemfile. Think about it…there’s very few other files that contain so much information. It describes the building blocks of the application. And at times, you can even see specific features of the application.

continue reading →

If you’ve used validates in a Rails Active Record model, you know they work great – at least until the first bit of complexity arises. At that point, they can quickly morph in to a ball of conditional spaghetti convoluting the initial reason the validation was added in the first place.

I recently had an experience using has_secure_password where I wanted control the length of the user-supplied password. Adding a length validation to the password accessor invalidated existing records, so I was in a bit of a bind. In the end, I sub-classed the Active Record model to create a unique model made specifically for that context. This allowed me to inherit the core functionality from the model and sprinkle on existing validations for specific use cases. This was a new tactic for me and I’m still not sure how I feel about it. I like the fact that it removed complexity from the User model. This, in hopes, will keep the minimize the likelihood of it becoming a God object.

continue reading →

Last month marks the 6 month anniversary of the release of Build a Ruby Gem. Thinking back to this time last year, I would’ve never guessed that I would launch a product to the tune of $16k+ sales in 6 months. Thanks to the help of expert teachers, I was able to quickly get over my fear of marketing and put my technical knowledge to good use.

The weeks leading up to the launch seem like a blur now. At the time, I had a perfectly crafted schedule of marketing material and approaches that, as far as I can tell, were the difference between no sales and quite a few.

continue reading →

It’s been awhile since my last post — almost 2 months to be specific. A trip to Portugal, getting sick and a minor run-in with a table saw made it challenging to post anything for the last couple weeks. But I’d be lying if I said I was itching to write.

During that time, I didn’t have anything screaming to be talked about. I have a long list of “decent post” topics, but none of them got me particularly excited. Until today…

continue reading →

I previously wrote about how I handle environment configuration in Rails. Along with solutions like the dotenv gem, it relies on entirely on environment variables.

One of the highlighted features of Rails 4.1 was the config/secrets.yml file. By default, this file contains the secret_key_base and defers to the ENV variable of the same name in the production environment. Even though secret_key_base isn’t typically referenced explicitly in an application, I was curious if I could use the config/secrets.yml file in place of previously documented configuration solution.

continue reading →

I’ve been fortunate to spend the last month as the sole developer of greenfield Rails 4.1 app. As someone who’s spent quite a bit of time maintaining existing code, the freedom to establish patterns and choose tools is a highly welcomed change. One of the choices I made was to use Minitest and Rails fixtures.

The short is…it’s been great! So great that I’m having trouble imagining myself using anything else going forward.

continue reading →

I’ve recently had the good fortune of working on a greenfield Rails app. The app is heavily dependent on times and recurring events (weekly). Naturally, I dragged in the timecop gem to handle freezing time, so my I could properly assert that certain events took place in the tests.

With the release of Rails 4.1, the time stubbing method travel_to was added. This new helper method forces the current time to whatever you specify, allowing you to make asserts against a historical time, or week in my case.

continue reading →
Build a Ruby Gem Course - FREE!

Join 1,300+ other Rubyists and take your Ruby gem skills to the next level!

Whether you're an expert Rubyist, or just starting out, this FREE 10-day email course will guide you through the process of creating your own Ruby gems from start to finish.

Enter your email below to get started today: