Skip to content

Instantly share code, notes, and snippets.

@rsslldnphy
Created May 20, 2013 10:03
Show Gist options
  • Save rsslldnphy/5611395 to your computer and use it in GitHub Desktop.
Save rsslldnphy/5611395 to your computer and use it in GitHub Desktop.
Options used for dealing with missing records
## Model code
class Customer < ActiveRecord::Base
def find_by_name(name)
Option[where(name: name).first]
end
end
## Controller code
class CustomersController < ApplicationController
def show
Customer.find_by_name(params[:name]).match do |m|
m.some { |customer| @customer = customer }
m.none { render text: "Error - customer not found" }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment