Sohaib.io

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 == 'john'

Hacking and adding custom helpers to Ghost

Deprecated. The blog post was for Ghost v0.3.2. Things have changed. Please do not try the following below Warning: The code I'm about to mention below isn't a good practise. As far as I am aware, Ghost does not currently support adding custom HandleBar helpers but plan on

Importing dates from spreadsheets in Ruby

I encountered an interesting issue yesterday. While importing data present in an xlsx file, I noticed that dates present in the excel file were being imported as numerical floats. My original code below DATE_COL = 10 2.upto(10) do |i| ... excel_file = Excelx.new("#{Rails.root}/temp/final_cand/

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

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

Sohaib.io © 2026