Sha256: bcae27d5f124bfdec08e8df2ad55ef8922dd7413670d6f3c30e586e0402b744b

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# The Comment model. This model is automatically generated and added to your app if you run the commenting generator.

class Comment < ActiveRecord::Base

  # If database speed becomes an issue, you could remove these validations and rescue the ActiveRecord database constraint errors instead.
  validates_presence_of :name, :email, :body
  validates_format_of   :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i

  after_validation :prepend_url
  
  # Set up the polymorphic relationship.
  has_many_polymorphs :commentables, 
    :from => [<%= commentable_models.join(", ") %>], 
    :through => :commentings, 
    :dependent => :destroy,
<% if options[:self_referential] -%>    :as => :<%= parent_association_name -%>,
<% end -%>
    :parent_extend => proc {
    }
    
  # Tag::Error class. Raised by ActiveRecord::Base::TaggingExtensions if something goes wrong.
  class Error < StandardError
  end

  protected
  def prepend_url
    return if self[:url].blank?
    if self[:url] !~ /^http(s):\/\//i
      self.url = 'http://' + self[:url]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
has_many_polymorphs-2.11 generators/commenting/templates/comment.rb