Why I still prefer Thin Models in Rails

“Fat models, skinny controllers.” That was the mantra for years. But if you’ve ever worked on a Rails app that’s more than two years old, you know where that leads: a User.rb file that’s 2,000 lines long and handles everything from authentication to generating PDF invoices. The Problem with Fat Models When a model knows too much, it becomes impossible to test in isolation. You want to test a simple validation, but you end up triggering five callbacks that send emails and ping Slack hooks. ...

February 11, 2026 · 2 min · Chen Kinnrot

Rails Presentation Objects

If you ever used any MVC framework, I’m sure you asked yourself more than once, ‘Where should I put this piece of code?’ (If not that’s also fine). Well, there is no one answer for all problems but, I asked it a lot. In this post, I’m gonna focus about the view part. View objects, AKA view models, but any other name is fine (presenter view object, view controller mediator, whatever). ...

February 23, 2020 · 4 min · Chen Kinnrot

Building your own rails form builder

If you’re building forms with rails, whether you’re using a gem for it or working with pure rails forms, you should know this. Rails uses form builder to allow you to call all the standard label/input/select methods, the exact class name is ActionView::Helpers::FormBuilder When calling ‘form_for’ you get a fresh instance of this FormBuilder which allows you to define your form elements. Lets say you wanna add another reusable form element, for example a form section with title that uses your own custom style/classes. ...

August 7, 2019 · 2 min · Chen Kinnrot

From jQuery to Stimulus

I tried to build an SPA without a shiny client side framework, I wanted to build something fast with good user experience and keeping it as simple as possible. I decided to take rails, use turbolinks and a avoid javascript till its a must. It didn’t take more than a few hours and I found myself writing javascript. What I needed to do is simple, I had an input with number, and 2 buttons next to it, one to increase values by 1 and on to decrease it looked like this: ...

May 22, 2018 · 4 min · Chen Kinnrot

Get the user locale from http headers

If you want to provide default localization support for guest user in your website yo can locate their browser locale by the following code: def extract_locale_from_header unless request.env[‘HTTP_ACCEPT_LANGUAGE’].nil? return request.env[‘HTTP_ACCEPT_LANGUAGE’].scan(/^[a-z]{2}/).first end ‘en’ end This way you can determine on server side the locale of the user currently entered your site.

November 15, 2014 · 1 min · Chen Kinnrot

Dedicating a DJ(Delayed job) worker to a specific queue in heroku.

Let’s say you have a vey important procedure that takes a while, and you need to process it in background, but you still want to execute ASAP. I’m using Delayed Job on Heroku, and could not find a lot of tutorials to do this simple task. So here is the simplest way to achieve this ability, you can raise a process/daemon that will have only one queue to work on. (Dealyed job worker by default is queue agnostic, just process all jobs) In procfile: urgentworker: QUEUE=urgent bundle exec rake jobs:work You can call the worker in any name you want and even define multiple workers for multiple queues. And in the “urgent” job just define the queue name to be “urgent” the worker will process only jobs in this queue. example: handle_asynchronously :some_job, :queue => “urgent’ This will also work for Resque. Notice that for rescue you can write QUEUE=* but for delayed job you can’t.

November 15, 2014 · 1 min · Chen Kinnrot

Rails + Mongo + Heroku how?

After a few hours of fighting with google I decided to write it all here: *This post is more relevant for windows users but can help others. What do you need to have: First you need to have ruby 1.9.2+ Devkit then you need rails 3+ then u need the bundler gem then go to getting started with mongoid then install mongo locally then check it all good then add account in heroku then create app then add your key then push

March 28, 2012 · 1 min · Chen Kinnrot