By Nathan L. Walls

  • Empty Cup/Raleigh
  • Jake/Raleigh
  • Silhouetted Palms/Phoenix
  • Landing Clouds/Raleigh

Articles tagged “rails”

RailsConf 2017 talk: "Exploring the History of a 12-year-old Rails Application"

I’m proud to share the video of my talk, “Exploring the History of a 12-year-old Rails Application” from RailsConf 2017.

The full video is below.

You can find slides on Speaker Deck. Confreaks also has page for the talk.

This was the largest group I’ve presented to so far. While work began on the talk in February, 2017, I ended up working on it until about 45 minutes before I went on stage. I’ll have a separate “lessons learned” post about the talk and things I would like to do with the talk material in the future, focused primarily on some data I wanted to analyze in more depth, but did not get to.

That said, I enjoyed the heck out of putting this talk together and presenting. I could sense that points I wanted to emphasize were coming across based on the audience’s body language. The coworkers who directly experienced the circumstances I walk through in the talk said I represented those times well. I’ll take all of that as a win.

My thanks to Confreaks for their recording and production work.

Rails 3 – Solving NoMethodError -- undefined method for Markdown

I just switched an app from Rails 3.0.0.beta4 to Rails 3.0.0 and while poking around the app, I started getting the following error:

FooController raised exception: NoMethodError -- undefined method `markdown' for …

It took a bit of hunting through the Rails project history, but I found the relevant commit. In short, text helpers for Textile and Markdown were removed from Rails 3.0.0.

What wasn’t so obvious from actionpack/CHANGELOG was why the change was made.

Thankfully, there is a gem to add the helper methods back in. Give Formatize a look. Adding it to your Gemfile should resolve any NoMethodError exceptions

Ruby on Rails phone number validation

I recently launched a Rails application that has a phone number field available to it. In the process of writing my spec tests, I allowed the phone field to be a certain number of characters and allowed it to be empty. The formatting test, however, I left pending. I searched for, but did not find a great solution past some very unreadable regular expressions.

In the course of watching a movie this evening, I had a solution. I created an array of acceptable formats, looped over the array and checked each entry against the phone number. If I had a match, the validation passes. Setting the string match to the beginning and I can allow for extensions without being too persnickety about formatting.

Here it is (via a handy gist):

def valid_phone
  return true if phone.blank?

  phone_formats = [
    /^\(\d\d\d\) \d\d\d-\d\d\d\d/,

  valid = false
  phone_formats.each do |format|
    if phone.match( format )
      valid = true

  unless valid
    errors.add("Phone format isn't recognized")

Here are some spec test examples.

It doesn’t handle international formats, but, for right now, it fits my needs.

← Previous Next →