Every developer is different. Each of us have their favourite code editor or operating system. Everyone listens to different music while working or doesn’t listen to music at all. We may have different personalities, and preferences but we all share one thing for sure. That one thing is called Gemfile. When I looked through my last few projects I have noticed a few gems that repeated, whouthout fail, in each app. I want to you to present you the 5 gems that you will love or hate.

Pry

When I started to learn Ruby on Rails, my biggest problem was how to understand what I have done wrong. Some of you may know Microsoft’s IDE called Visual Studio. This is a very powerful tool that includes debugger tool. You can simply ‘toggle breakpoint’ in the line you want and when the program steps into this line, it will stop and you will have immediate lookup on all the variables at this particullar moment.

Some time ago, my friend showed me Pry gem. Wow. That was like the missing link. It works similarly to the Visual Studio debugger. When you want your application to stop in a particullar moment you simply type:

binding.pry

When an application steps into this line it will stop. And in the terminal where you have started your rails server you will have something like ‘live console’. You can easly debug your variables there instead of making ‘puts’ or ‘p’ everywhere. Example of how it works below:

Of course this is not the only feature of this gem. It will ‘rebuild’ your irb console also. Just give it a try and I promise, from now on you will always have it in your Gemfile.

Better errors

Let’s stick to the debuging area for a while. You often get an rails app error screen. What if there is a gem that shows you this error in a beautiful way? Fortunately there is Better errors. Moreover you can have a live shell if you add Binding of caller. Errors with those gems just seem more friendly and don’t bother me that much.

Reform

There are projects where you need to build some crazy form that has some nested attributes, some terms accepting and stuff like that. It’s a good practice to build a form object in order to handle this easily. Reform gives you maximum options for minimum code. Every form object inherits from Reform::Form. You just define fields (as properties) and write validations to them. I can write a whole blog post about the possibilities that this gem gives you, but it’s not the point. Go check it out yourself.

Draper

Do your haml views contain many lines like this:

-if @user.something
  %p User is something
-else
  %p User is not something

or

=@user.publication_date.strftime("at %I:%M%p")

then you definitely would like to use some presenter pattern or in this case – decorator. By usingDraper you can have a place for some logic that needs to be included in the view. A view should be easy to read and adding more and more ‘if-else’ or some ‘polishing’ methods won’t help at all. Thanks to draper, all view-model logic can go into the decorator and the view itself will be only responsible for displaying the data.

Paloma

There is a place in ruby on rails app for placing javascripts. Even so, you need to explicity make a call in your views in order to invoke the javascript function. Thanks to Paloma we can organize javascripts in a more ‘clean’ way. You can read more about it in Kamil’s post: “Keeping scopes clean while coding in javascript.

Bonus

This is a must for all developers. But don’t tell it to anybody. This will be our secret. It’s a key to write typo-less application without even bother to check typos. Here’s some code that will illustrate what happens when you start using this gem:

ourLife.rotate(180)
Post tags:

Join our awesome team
Check offers

Work
with us

Tell us about your idea
and we will find a way
to make it happen.

Get estimate