Creating a local copy of the routes.rb file to speed up your grepping of the routes

10/08/16  Public, Command Line, Rails General

Grepping your routes.rb file, for decent size projects, can take a long time. One solution to speed up this process is to create a local copy of the current state of your routes.rb ...

1 vote - harrylevine

before_* callbacks rollback transactions if its method returns false

10/05/16  Public, Rails Errors, Troubleshooting

I had a form, where in one of the fields, the user was clicking a drop-down menu, and choosing between one of three choices.

After the form was submitted, I had a callback that was doing something to the record.

When the user selected op...

1 vote - harrylevine

Encode an SVG file using base64 encoding

09/22/16  Public, Command Line, Tricks, Other Languages

Here is how to encode an SVG file, using base64 encoding, and then leverage the encoded string to set an element's background-image property to the SVG file in question.

1 - Open up an irb session
2 - Read the file into a variable, using...

1 vote - harrylevine

Controller spec when controller method is being hit through AJAX

07/29/16  Public, Testing / TDD

I had a controller method that is being called via AJAX. This method does not specifically render any pages (i.e. update.html.erb). The controller spec was throwing a missing template error

Failure/Error: put :update,
ActionView::Miss...

1 vote - harrylevine

`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