This file contains 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
class Storefront < ActiveRecord::Base | |
extend WebsiteValidation | |
validates_website :website | |
end |
This file contains 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
module WebsiteValidation | |
def validates_website(column_name) | |
validates do | |
unless __send__(column_name).blank? || __send__(column_name) =~ /^http:\/\/|^https:\/\// | |
__send__("#{column_name}=", "http://#{website}") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment