`update_all` does not trigger callbacks or validations

07/25/16  Public, Rails General

We usually use custom validations or callbacks on the model, when we want to throw a large net and catch everything.

Something to be aware of is that update_all does not trigger callbacks or validations.

1 vote - harrylevine

Dealing with a LocalJumpError

06/20/16  Public, Troubleshooting, Ruby General

This is commonly caused by having return called within a block.

Here is an example. This example triggered an Airbrake error of type LocalJumpError:

task :decrement_taken_pto_...

1 vote - harrylevine

Rollback or forward just one migration file

01/17/17  Public, Command Line, Rails General

You can rollback, or forward, just one migration file, regardless of where it is in the stack. Thereby putting it in either the down, or up, status.

Here is the syntax:

rake db:migrate:down VERSION=20160506010740
rake db:migrate:up V...

1 vote - harrylevine

Using the ruby #inject method

06/16/16  Public, Ruby General

I had this method to start with:

NON_DEDUCTIBLE_REASONS = ['Jury Duty', 'Bereavement']

def self.attendance_status_ids
  ids = []

  NON_DEDUCTIBLE_REASONS.each do |reason|
    ids << AttendanceStatus.find_by_name(reason.to_s.t...

1 vote - harrylevine

Using a backtrace with byebug for debugging

06/02/16  Public, Testing / TDD

When you get the byebug prompt, enter bt:

(byebug) bt

1 vote - harrylevine

Helpful site for writing Regular Expressions

05/02/16  Public, Other Languages


Rubular is a Ruby-based regular expression editor. It's a handy way to test regular expressions as you write them.

1 vote - harrylevine

Creating a scaffold migration in Rails

08/21/16  Public, Rails General

1 - Make sure you have already created your rails app
2 - $ rails generate scaffold topic title:string description:text

This generate scaffold tells Rails to create everything necessary to get up and running with topics model.
- `topi...

1 vote - harrylevine

Rescue in failing controller spec

04/01/16  Public, Testing / TDD

I was getting a failing controller spec, and the failure message was not helpful at all, nor were any of the debugging approaches. A coworker recommended that I check the controller method itself to see if there is a rescue block in there. Low...

1 vote - harrylevine

Shortcut for pretty printing Active Record data in the rails console

03/28/16  Public, Command Line, Shortcuts, Tricks

In the rails console, when you run something like Post.all it returns all of the posts in one big continuous paragraph. A quick, low-rent shortcut to get these records to pretty print is to:

  • lead with a y

For example:


1 vote - harrylevine