Skip to content

Instantly share code, notes, and snippets.

@benmacleod
Forked from radar/gist:6374310
Last active December 21, 2015 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmacleod/6374314 to your computer and use it in GitHub Desktop.
Save benmacleod/6374314 to your computer and use it in GitHub Desktop.
def self.find_by_id_or_first(id)
(id && where(:id => id).first) || first
end
# or...
def self.find_by_id_or_first(id)
order("id = #{id.to_i} DESC").first
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment