Posts for Tag: rails

Commonly used (and abused) Ruby Gems

Following up on my last post about Ruby gems, here's a list of some of my typical choices for various tasks in the Ruby and Ruby on Rails world:


Makes it real easy to define exactly how to serialize models in an API


Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema. Very cool to know exactly which fields are present in your models, without having to look it up in the schema.rb file.


Great Ruby dubugging companion: pretty print Ruby objects to visualize their structure. Supports custom object formatting via plugins.


The Amazon Web Services SDK allows you use those services with ease. Especially great as a backend for paperclip attachments.


Brakeman detects security vulnerabilities in Ruby on Rails applications via static analysis. Just install and run it at your RoR root folder.


A Ruby notifier for It allows you to receive debug emails when stuff is broken in production. Priceless.


Simple authorization solution for Rails. All permissions are stored in a single location. Allows you to define who has access to what in your RoR in a very simple way.


Chosen is a javascript library of select box enhancer for jQuery and Protoype. This gem integrates Chosen with Rails asset pipeline for easy of use.


This gem provides CKEditor driver for your Rails 3 application. CKEditor is the the fastest and easiest way to integrate a rich text editor into your application.


Flexible authentication solution for Rails with Warden. Extremely modular way of authenticating users in your app.


Everyone knows devise, but not everyone knows there is a gem with translations (i18n) for most languages. 


factory_girl provides a framework and DSL for defining and using factories - less error-prone, more explicit, and all-around easier to work with than fixtures. Basically allows you to create model instances for your tests in a very easy manner.


factory_girl_rails provides integration between factory_girl and rails 3 or newer (currently just automatic factory definition loading). The simplest way to start using factory_girl in a RoR app.


Simple, Heroku-friendly Rails app configuration using ENV and a single YAML file. Another way to manage env variables in a cross environment way would be rbenv-vars. But figaro also works really well.


Process manager for applications with multiple components. Just create a Procfile with the processes you wish to start and fire foreman. It will dump the logs in different colors per process to make it easier to read.


Makes http fun! Also, makes consuming restful web services dead easy. Allows you to make a REST call to wherever and get the results properly parsed into a Ruby hash, independently of the response format (XML, JSON, etc).


It's a small library to provide the Rails I18n translations on the Javascript. No more interpolation from slim, haml, or erb for translations. Just use plain javascript.


Generates javascript file that defines all Rails named routes as javascript helpers. Same as above but for rails routes instead of localizations.


This gem provides the leaflet.js map display library for your Rails 4/5 application. Leaflet is an awesome javascript abstraction to handle a map on a webpage, agnostic to the map provider itself. You can use OpenstreetMaps, Mapbox, Bing and other map tile providers.


Materialize ( set up for the Rails 4+ asset pipeline. Beautiful Material Design by Google at your fingertips.


Do you know Capistrano? Meet Mina, a blazing fast application deployment tool. It opens only one ssh connection for all commands, so it's a gazillion times faster than good old cap.


Rails gem for dynamically adding and removing nested has_many association fields in a form. Uses jQuery and supports multiple nesting levels.


New Relic is a performance management system, developed by New Relic, Inc ( New Relic provides you with deep information about the performance of your web application as it runs in production. They have a free tier so you can keep an eye in your web app in terms of performance without any cost.


Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser. Among Nokogiri's many features is the ability to search documents via XPath or CSS3 selectors. If you need to do any XML manipulation, or HTML scraping, this is your go to tool.


The fastest JSON parser and object serializer. Just drop it into any Rails application and get the instance performance increase in JSON handling.


Need to do some geocoding or reverse geocoding? Opencage has a free tier. This gem gives you the client to interact with their services.


Everyone knows the most common and easy upload management for ActiveRecord. Need an attachment on your models? Done.


Ransack is the successor to the MetaSearch gem. It improves and expands upon MetaSearch's functionality, but does not have a 100%-compatible API. It basically helps you build search forms for models in an easy way.


With webpacker you can already get React integration, but React on Rails can give you additional features, like:
  1. Server rendering, often for SEO optimization.
  2. Easy passing of props directly from your Rails view to your React components rather than having your Rails view load and then make a separate request to your API.
  3. Redux and React-Router integration
  4. Localization support
  5. Rspec test helpers to ensure your Webpack bundles are ready for tests


Display an elegant Github like ribbon to your Rails application showing environment informations (Rails environment, Ruby version, Rails version, ...). For example:


Nokogiri based 'have_tag' and 'with_tag' matchers for rspec 3. Does not depend on assert_select matcher, provides useful error messages. Makes it a breeze to test for presence of certain tags in an HTML response body.


One of the simplest, most efficient background processing tools for Ruby.


Enables you to setup sidekiq background jobs to be run at a specified time (using CRON notation).


Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic. Do you hate ERB's spaghetti syntax? So do I. Slim is a more Ruby'esc template system, based on indentation.


The Spreadsheet Library is designed to read and write Spreadsheet Documents. As of version 0.6.0, only Microsoft Excel compatible spreadsheets are supported. Spreadsheet is a combination/complete rewrite of the Spreadsheet::Excel Library by Daniel J. Berger and the ParseExcel Library by Hannes Wyss. Spreadsheet can read, write and modify Spreadsheet Documents.


Oldie but goldie, Stamp formats dates and times based on human-friendly examples, not arcane strftime directives.


Need to do some reporting and don't want the hassle of handling XML to pass to Jasper Reports? Try ThinReports, an open source report generation tool for Ruby.


Adds validation methods to ActiveModel for validating dates and times. Works with multiple ORMS.


will_paginate provides a simple API for performing paginated queries with Active Record, DataMapper and Sequel, and includes helpers for rendering pagination links in Rails, Sinatra and Merb web apps.


Adds Dropzone, a great JS File upload by Matias Meno, to the Rails Asset pipeline. DropzoneJS is an open source library that provides drag’n’drop file uploads with image previews. It’s lightweight, doesn’t depend on any other library (like jQuery) and is highly customizable.

Problem starting Sidekiq in development

If you ever get this error:

can't link outside actor context

Followed by something like:

    /Library/Ruby/Gems/2.0.0/gems/celluloid-0.16.0/lib/celluloid.rb:176:in `new_link'
    /Library/Ruby/Gems/2.0.0/gems/sidekiq-3.3.4/lib/sidekiq/launcher.rb:21:in `initialize'
    /Library/Ruby/Gems/2.0.0/gems/sidekiq-3.3.4/lib/sidekiq/cli.rb:81:in `new'
    /Library/Ruby/Gems/2.0.0/gems/sidekiq-3.3.4/lib/sidekiq/cli.rb:81:in `run'
    /Library/Ruby/Gems/2.0.0/gems/sidekiq-3.3.4/bin/sidekiq:8:in `<top (required)>'
    /Library/Ruby/Gems/2.0.0/bin/sidekiq:23:in `load'
    /Library/Ruby/Gems/2.0.0/bin/sidekiq:23:in `<main>'

It's mostly likely somehow related with either ZenTest or another testing framework. 

In my case, i was adding the ZenTest gem both in the development and test groups of my Gemfile. Moving it away from the development group solved the problem.

Date and time in ruby will give you the current date (and time), like so: 2012-11-22 22:35:01 +0000

You can also request all the date parts individually: 22 35 01 22 11 2012

Cool (and easy), right? If you want to change a date, you can add seconds to it:

t = 2012-11-22 22:35:01 +0000 t2 = t + 10 # 10 Seconds 2012-11-22 22:35:11 +0000 t3 = t + 10*60 # 10 minutes 2012-11-22 22:45:01 +0000 t4 = t + 10*60*60 # 10 hours 2012-11-23 08:35:01 +0000

If you happen to be developing a Ruby on Rails application then it gets even easier:

t = 2012-11-22 22:35:01 +0000 t2 = t + 1.hour 2012-11-22 23:35:01 +0000

That&#39;s right, in Rails numerals get some extra methods injected into them, like hour, hours, minute, minutes, second, seconds, day, days, and so on... And people still ask me why i love Ruby (and Rails)... :)

A collection of useful Ruby/Rails gems

Since lately i&#39;ve been working a lot with Ruby (Android and Java&nbsp;as well, but that&#39;s a different story), i figured i posted a couple of interesting gems that will make your life easier, especially but not only for rails.


Slim is a templating engine (like ERB or HAML) which pursues simplicity. It helps you write an insane amount less HTML and Rails code. You will not believe your eyes. An example:


&lt;body&gt; &lt;h1&gt;Markup examples&lt;/h1&gt; &lt;div id=&quot;content&quot;&gt; &lt;p&gt;This example shows you how a basic Slim file looks like.&lt;/p&gt; &lt;%= yield %&gt; &lt;/div&gt; &lt;/body&gt;

The same in Slim

body &nbsp; h1 Markup examples &nbsp; #content &nbsp; &nbsp; p This example shows you how a basic Slim file looks like. &nbsp; &nbsp; == yield

Now tell me which one you prefer to write ;)


A fantastic tool to format dates based on human readable formats. Why use;%Y/%m/%d&quot;) when you can use;2012/12/13&quot;)? Sweet, right?


Bugsnag is web site exception grabbing on steroids. It basically monitors your website alerting you of any exceptions and providing the relevant information needed so you don&#39;t have to debug your production server.

Cool thing is, there are &quot;bindings&quot; for multiple languages and frameworks. You can find the one for Ruby/Rails here.&nbsp;

Honey Badger

Honey badger has a really simple purpose: To make sure you know which server you are in (say, testing, dev, production) by displaying a small &quot;badge&quot; with the name of your choosing.

If you are like me you can easily think you are debugging something in testing when you are really looking at production. Ok, maybe that&#39;s just me, but the badge does look cool, right? :)


Now, i&#39;m not one to call the name of the Lord in vain (i am!), but God is something i can no longer do without. It&#39;s a process monitoring framework written in ruby that keeps an eye on your server&#39;s, say nginx, apache or mysql and makes sure they are always up.

Further checks can be done, like for example restart the server when memory usage goes above X or CPU usage goes above Y. It is also capable of notifying you by email, jabber, twitter, you name it, when things happen. It&#39;s a true life saver :)

Hope you find these gems useful, as i did, and if you have some that i might find interesting, please do share via twitter :)

Introducing Simple Rails Blog

Yes, a new blog. I know what you are thinking: &quot;Who the hell cares?&quot;. But read me out.

A while back i looked at wordpress and thought &quot;i don&#39;t really need all this stuff, do i?&quot;. Turns out i didn&#39;t. And if you are at least a little bit like me you will agree that sometimes less is more. After searching for some alternatives i ended up with two solutions: A company hosted blog (tumblr, blogger, and others) or hand made. I chose the latter.&nbsp;

So let me introduce you to my new open-source Rails blog. Developed with simplicity in mind, it allows you to write and (easily, even automatically) tag posts. That&#39;s it.

Full source code is available at bitbucket. If you are a Rails developer (or a plain developer with an open mind) you will find it trivial to adapt it to your needs.

Enjoy, Pedro