Skip to content

Instantly share code, notes, and snippets.

@Iknewthisguy
Created August 7, 2012 15:01
Show Gist options
  • Save Iknewthisguy/3286103 to your computer and use it in GitHub Desktop.
Save Iknewthisguy/3286103 to your computer and use it in GitHub Desktop.
Module Refactoring - Sample Model
class User < < ActiveRecord::Base
def self.find_by_vanity(vname)
#m = User.find vname
v = Vanity.find_by_name(vname)
m = v.try(:vanity)
#if we couldnt find by Vanity, lets try finding by regular id:
unless v and m
begin
m = User.find!(vname)
rescue NativeException
raise Neo4j::Rails::RecordNotFoundError
end
end
return m
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment