Classes vs Modules for Obese Models

The concept of Thin controllers and fat models is preached heavily to individuals who are just picking up Rails. In my opinion the same concern should be extended to models as well. Quite often is it the case that models in a Rails app tend to get really large(1000

Written By
Sohaib Talaat Bhatti on Refactoring, Service Objects, Rails, Ruby

Interesting Rails Feature - Active Model Dirty

This feature isn't used nearly as much as it deserves to be. ActiveRecord objects keep a track of whether any of their attributes values have changed via the ActiveModel::Dirty module. # Loading an object to memory user = User.find 29 # changed? lets us know whether any modifications were made to

Written By
Sohaib Talaat Bhatti on Rails, Ruby

Issues of Control Flow logic in Respond To Blocks

The following code was written by my boss to simulate an issue arising with a production app that I've been working on at work. class RacersController < ApplicationController def race @racer = Racer.first @was_in_if_block, @was_outside_if_block = false, false respond_to do |format| if @racer.name

Written By
Sohaib Talaat Bhatti on Rails, Bug

Interesting Rails Feature - Partial Counters

While working on a Ruby on Rails project, I stumbled across an interesting feature. = render partial: 'product_line', collection: product_lines_with_brand(@result, brand) In my view I was rendering the partial above. For styling reasons I required that after ever second time the partial is called, I should

Written By
Sohaib Talaat Bhatti on Rails, Ruby