Skip to content

Instantly share code, notes, and snippets.

@amitsaxena
Created December 14, 2012 16:17
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 amitsaxena/4286604 to your computer and use it in GitHub Desktop.
Save amitsaxena/4286604 to your computer and use it in GitHub Desktop.
class Link < ActiveRecord::Base
validate :url_presence
def url_presence
errors.add(:base, "#{Link.url_label(linktype)} can't be blank.") if url.blank?
end
def self.url_label(linktype)
{"web" => "Web URL", "video" => "Video URL", "audio" => "Audio URL", "ecommerce" => "Shop URL",
"page" => "Page number", "email" => "Email"}[linktype] || "URL"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment