Since joining Haught Codeworks as an apprentice one month ago, I’ve spent a lot of time working with two particular gems, Administrate and Devise, in two different apps. This has led me to think about the magic and potential convenience that come with gems versus the customization and knowledge that come with building something yourself.
When it Doesn’t “Just Work”
Gems can be a helpful way to make something “just work,” like authentication with Devise and an administrator dashboard with Administrate. However, when something goes wrong, or doesn’t work as expected, it can be hard to find out why. Remember that when you’re using a gem, you’re counting on someone else’s code rather than your own. Take the time to read the available documentation and look through the gem’s source code. Know where different parts of the gem function in your app, and try to understand how it all works together.
Since Administrate is a relatively new gem, I found that the issues section of their GitHub site was very active. I was often able to find the answer to my questions there, and if a feature I was hoping for didn’t exist, I could comment on an issue and quickly receive a response.
Customizing a Gem
Gems can add a lot of functionality to an app without the developer needing to write many lines of code, but when you want to customize something, it can be hard to know where to begin, especially as an apprentice or a junior. I’ve spent a fair amount of time changing things in Administrate to fit the needs of users, and it was a challenge at first to figure out how everything was linked together and determine what views and controllers I needed to generate in order to customize the appearance and functionality of our admin pages.
Now that I’m getting to know the code behind Devise and Administrate, and I better understand how they fit in to our apps, I can more effectively work with the gems and customize them as needed.
When to Gem & When Not to Gem
It can be tempting to search for gems that will add a desired function to your app, but before blindly dropping a gem in your Gemfile and bundling, be clear on what it does. Does it do one small thing really well, or does it touch many parts of the app? Devise and Administrate both add their own routes, controllers, and views. Before installing a gem of this scale, make sure you know how to modify the gem’s functionality if need be, and beware of too much coupling between different parts of your app. There is a speed advantage to using gems, but if you’re relying too much on magic or plan to do a high level of customization, you’re often better off rolling your own solution.