Top Ruby gems you can’t miss in 2019
It took us three long years to give you an update on the best Ruby gems our devs find the most useful in their work. But, well, here it is. We are extremely pleased to bring you the list of gems you simply cannot miss in 2019.
Bearing in mind that you are here and reading this post, I presume you are no stranger to the world of Ruby on Rails and know the term “gem” pretty well. No? Let's set the basics before we get into the details.
What is Ruby on Rails?
Ruby on Rails (also named Rails or RoR; also incorrectly referred to as Rubies on Rails) is a web development framework released in 2004 and built upon the Ruby language that has first emerged in the 90s. Over the 15 years of usage, Rails has been used for websites and web applications. Its main pros as short development time, cost-effectiveness have been leveraged by such giants as Basecamp, Airbnb and Shopify among others. Check what other websites are using Ruby on Rails.
What is a gem?
One of the greatest strengths of RoR is a huge community of contributors, which is now circa 4,000 strong on GitHub.
A gem is a ready, reusable solution to de facto standard problems contributed by the Ruby on Rails community.
Gems keep Ruby on Rails stable and thriving and are free to use by any Rails programmer. They make programming in Ruby on Rails much faster, as software developers don't need to write certain parts of code from scratch. Shorter development time, on the other hand, means lower costs, which makes Rails good for MVPs (minimum viable products).
The number of available gems is so huge that a community saying was forged some time ago that goes: "There is a gem for that".
If, for some reason you need a reminder, just check our Ruby Gem Guide, containing the list of our favorite gems from 2015. But life goes on, and the universe of Ruby has welcomed several valuable additions, while seeing other gems go. This is why I decided to ask the Prograils developers about the best Ruby gems they have been using in 2019. What are they and what kind of magic do they do? Let us see!
1. ActiveRecord Import
activerecord-import
A gem enabling fast insertion of bulks of records. activerecord-import
follows activerecord associations and generates the minimal number of SQL insert statements required, avoiding the N+1 insert problem. As the plain ActiveRecord may work fine when uploading ten, but not hundreds or thousands of records, this gem is extremely useful when importing external data. Simply said, activerecord-import
reduces the conversion time significantly.
2. Primary
primary
primary
provides an easy way to mark a record as "primary" (or "active", "selected", etc.) for a given scope. If your site has, for instance, several languages, this one will choose one of them as the default one.
3. Rollout
rollout
This plugin allows us to gradually roll out features to selected users.
4. Pry, Pry-Rails, Pry-Byebug, Pry-Remote
pry
A must-have set of gems for any Rails developer that makes debugging a pleasure. pry
is written from scratch in order to ensure a number of advanced features including source code browsing, syntax highlighting, live hel system and a wide range of plugins providing remote sessions and full debugging functionality.
5. Wicked PDF
wicked_pdf
A gem that generates PDF files from Rails templates. Instead of dealing with some PDF generation DSL, you simply write a Rails view as you would normally and then let wicked_pdf
take care of the rest.
6. Cocoon
cocoon
This one handles nested forms and has already replaced the long-undeveloped nested_form
gem. Nested forms are forms that handle nested models and attributes in one form; e.g. a project with its tasks or an invoice with its line items. Compatible with Rails 3, 4 and 5.
7. Grape
grape
A REST-like API framework for Ruby. It's designed to run on Rack or complement existing web application frameworks such as Rails and Sinatra by providing a simple DSL to easily develop RESTful APIs.
8. Rake
rake
This is a Make-like program implemented in Ruby with tasks and dependencies specified in standard Ruby syntax. You notice the Make reference with R for Ruby instead of “M”, right?
9. Webpacker
webpacker
Provides integration with webpack and yarn in your Rails app. The main purpose of webpacker
is to serve JavaScript, as well as assets like CSS, images, and fonts for component-based JavaScript, but it is also possible to use it for your entire application's assets. Read more about adding webpacker to a legacy Rails app
10. Bullet
bullet
Designed to increase an application's performance by reducing the number of queries it makes. Bullet keeps an eye on them while the app is being developed and will notify you whenever eager loading (N+1 queries) is required, or when it isn't necessary and when counter cache should be used.
11. Geocoder
geocoder
There are many reasons for you to have this ace up your sleeve, actually. geocoder
performs multiple functions. Thanks to it, you can both forward and reverse geocoding as well as an IP address geocoding. What is more, it connects to more than 40 APIs worldwide. Thanks to an advanced configuration, you will be able to use different parameters and APIs under various conditions. Features like caching will definitely enhance your app’s performance. geocoder
integrates with ActiveRecord and Mongoid. Its basic geospatial queries include search within radius, rectangle or ring.
12. VCR
vcr
This one lets you record your test suite's HTTP interactions and replay them later during future test runs. Profits? Fast, deterministic, accurate tests.
13. ParallelTests
parallel_tests
The main function of ParallelTests is separation of tests into even groups (be it by number of lines or runtime) and running each group in a single process with its own database.
14. Capistrano
capistrano
A framework for building automated deployment scripts. Although written in Ruby, capistrano
can be used to deploy projects of any language or framework. Rails? Java? PHP? You name it. When installed, this gem gives you a ‘cap’ tool for deployments straight from your command line.
15. Bundler Audit
bundler-audit
"Patch-level verification for Bundler" - as its creators describe. Enough said.
16. Shoulda Matchers
shoulda-matchers
As guys from Thoughtbot, who have created this gem, put it: shoulda-matchers
provides RSpec- and Minitest-compatible one-liners that test common Rails functionality. These tests would otherwise be much longer, more complex, and error-prone’.
17. Devise Masquerade
devise_masquerade
This one is a utility library which enables the login functionality as button for admin. If you want to test your multi-user app functionally by using a login of an existing user, though without asking them for the password - all you have to do is define login as a button with url helper and use it.
18. Sidekiq-Cron
sidekiq-cron
In order to schedule jobs at specified times, sidekiq-cron
runs a thread alongside all Sidekiq workers. It checks for new jobs to schedule every 30 seconds without scheduling the same job multiple times. Jobs are added only when at least one Sidekiq process is being run.
19. Ancestry
ancestry
Allows the Ruby-on-Rails ActiveRecord model records to be organized as a tree structure (or hierarchy). While using the materialized path pattern, it uses a single database column. All the standard tree structure relations can be fetched in a single SQL query. Other features? “STI support, scopes, depth caching, depth constraints easy migration from older gems, integrity checking, integrity restoration, arrangement of (sub)tree into hashes and different strategies for dealing with orphaned records”.
20. Turbolinks
turbolinks
Turbolinks allows for faster navigation in a web app. It brings the benefits of a single page application minus the complexity of a client-side JavaScript framework. No server-side cooperation is needed. The turbolinks gem provides back and reload buttons, which makes a web application serach engine-friendly. Support for mobile apps is also there.
Rails 6 is released with new features!
2019 has been a significant year for Ruby on Rails. After over two years of development works and thousands of commits, Rails 6 was released in August. The update, previously scheduled for this years Rails Conf, came with several new additions, including Action Mailbox, Action Text, multiple database support and many others. Take a more detailed look at new features in Rails 6 in this article.
UPDATE: You may have heard about Lit, our i18n gem for Rails apps translations...
If you are familiar with the first part of our Ruby gem guide, then you have certainly spotted the gem Lit, which we contributed to GitHub back in 2014.
Lit is a library which instals a web interface in your Rails app, allowing non-technicals to make translations of their apps themselves.
Since five years is long enough, we have collected feedback from our customers, the open source communtity, spotted areas for improvement, and here we are with the Lit v1.0 gem for making your Rails app's translation even easier!
Automatic cloud translation and "completed" status, as well as the "deleted and visited again" bar for restoring once-removed translation keys are among the new gem's highlights. You will also be able to import translation keys from .csv files and export them to this format.
So, if easy translation of your Rails app sound good to you, do give Lit 1.0 a try!
Last but not least: a huge “thank you” to Michał Buszkiewicz, Maciej Litwiniuk, Piotr Boniecki, Przemysław Nikratowicz and Piotr Wasiak for their valuable contribution to this post.
Recommended reads:
- Three ways of iterating over tree-like ActiveRecord structures
- Capistrano deploy to ubuntu, with systemd, nginx/puma and rbenv
- Learn more about our values, process and technologies. This is our playbook
Photo by Johnson Wang/Unsplash.com