10 Essential & Useful Ruby on Rails 4 GemsWeb Development
Updated on Saturday, July 12, 2014
Updated on Saturday, July 12, 2014
The Ruby on Rails framework is an extremely powerful tool for developing web applications. It comes with plenty of built-in features which help accelerate the development of your web application such as intelligent routing and an object-relation mapper, all using an MVC pattern.
Rails is designed in a way to be very easily extended using Ruby gems. This has created a large ecosystem of Ruby gems which can extend your application and accelerate your development process even more by reducing the time involved working in developing common functionality. We’re going to go over a few gems which we consider to be very useful.
Devise is most probably the most commonly used Gem when using Ruby on Rails. It provides an easy-to-use authentication solution for your Rails application which will allow you to get login, registration, forget password, account locks and much more account-related features by simply using this Gem.
It’s important to know the distinction between authentication and authorization. Devise helps authenticate users and verify who they are while authorization ensures that the user is allowed to perform an action or access a resource. Pundit takes care of this entire process by providing a simple way of defining authorization systems using nothing but Ruby classes.
There are many template systems out there. Ruby on Rails uses the eRuby template system by default, however, it’s typically something that users will choose to replace. Slim is a common replacement because it allows you to maintain very easy to read templates due to it’s simple syntax while maintaining very fast compilation times.
Draper allows you to build decorators around your models. It helps make your views much cleaner and lets you avoid writing helpers. Instead of procedurally calling helpers with models, you instead define a decorator which wraps the original model and provides a list of extended method and attributes to your object.
You’ll often re-use many components of your application. Typically, partials are used for this type of behavior however you must make sure that your controllers that call the partial all have consistent behavior. Cells allow you to take parts of your controller and encapsulate them into their own little controller. This helps make your code much cleaner and avoid the long helper/partial/filter mes.
Typically, resources URLs are identified by their primary key which is usually their database ID. However, this can result in unoptimized web page URLs which are not user-friendly to read either. FriendlyId can easily transform your URLs to much friendlier and easy to remember URLs for little to no code changes in your web application.
Forms are at the heart of every single web application. If there is any level of interaction with the user, it typically is done using a web form. Simple Form helps simplify this very simple yet repetitive task. By implementing a simple and easy to use DSL for building forms, you can spend less time writing HTML for your forms and more time on the core business logic of your application.
File attachments are never easy to work with. They typically involve a significant amount of work to implement and even more time to make sure that they are implemented in a very secure manner. Paperclip takes care of this entire process for you inside your Rails application and extends it even more to things like transforming images to thumbnails and much more.
Kaminari is not a very descriptive name for a Gem, however, it is one of the most popular Gems with almost 5 million downloads. It enables you to paginate anything from ActiveRecord relations to simple arrays using a clean, easy to use and simple scope-based API which is fully agnostic to whatever ORM or template engine you use.
There are many choices for background processing tools when using Ruby on Rails, however, Sidekiq is the one of the most popular ones. The reason behind it’s popularity is the simplicity of it’s API and how it scales much better than other background processors.