Add Utils to your rails app

Github /  Twitter  


There are many programming languages


we still use Ruby & Rails

From time to time any rails developer looks
on an another solution ,
plays with it

comes back to Rails

The framework does the dirty work   

introduces a lot of things that I has never thought about

The most useful rails parts


architecture  &  conventions

For more details watch a presentation about L ineman

With a rails convention it's always clear where any part of code should be placed & named

but in every application there were a chucks of code which I didn't know where to put

Yes, it's not a terrible situation & you could live with it. 

But there are a few problems

  • with app growth a count of these chunks increases too
  • some of them has a duplicated logic
  • it's harder to test it

time to search answers

They are good but your code becomes too much OO


gets a new problems with growth of files & classes

There should be something better 
more simple at the same time

Welcome utils

The idea is not new for IT world

  • object in Scala
  • namespaces(modules) in pure functional languages
  • Ruby singleton without share state & complication in method accessing 

A few lines to start using

As the result


  • get `helpers` but for all Rails application
  • take benefits  of a functional programming using Ruby
  • avoid creating new instances of classes
  • you know where to put not directly related "MVC" code

Use Cases





Also you could use Utils for:

  • generation collection for selects in view
  • parsing common params in controllers
  • other standalone stateless functions

IMPORTANT to avoid share state in Utils

For share state use an instance of a class


Utils in Rails

By Sergey Pchelincev

Utils in Rails

  • 1,732