2 # The Comment model. This model is automatically generated and added to your app if you run the commenting generator.
4 class Comment < ActiveRecord::Base
6 # If database speed becomes an issue, you could remove these validations and rescue the ActiveRecord database constraint errors instead.
7 validates_presence_of :name, :email, :body
8 validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
10 after_validation :prepend_url
12 # Set up the polymorphic relationship.
13 has_many_polymorphs :commentables,
14 :from => [<%= commentable_models.join(", ") %>],
15 :through => :commentings,
16 :dependent => :destroy,
17 <% if options[:self_referential] -%> :as => :<%= parent_association_name -%>,
19 :parent_extend => proc {
22 # Tag::Error class. Raised by ActiveRecord::Base::TaggingExtensions if something goes wrong.
23 class Error < StandardError
28 return if self[:url].blank?
29 if self[:url] !~ /^http(s):\/\//i
30 self.url = 'http://' + self[:url]