Created
May 20, 2013 10:03
-
-
Save rsslldnphy/5611395 to your computer and use it in GitHub Desktop.
Options used for dealing with missing records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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