Module: Opinio::OpinioModel::ClassMethods

Defined in:
lib/opinio/opinio_model.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) opinio(*args)

Adds the Opinio functionallity to the model You can pass a hash of options to customize the Opinio model



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/opinio/opinio_model.rb', line 14

def opinio(*args)
  return if self.included_modules.include?(Opinio::OpinioModel::Validations)
  options = args.extract_options!

  if Opinio.use_title
    attr_accessible :title 
  end
  attr_accessible :body

  belongs_to :commentable, :polymorphic => true, :counter_cache => options.fetch(:counter_cache, false) 
  belongs_to :owner, :class_name => options.fetch(:owner_class_name, Opinio.owner_class_name)

  scope :owned_by, lambda {|owner| where('owner_id = ?', owner.id) }

  send :include, Opinio::OpinioModel::Validations

  if Opinio.accept_replies
    send :include, RepliesSupport
  end

  if Opinio.strip_html_tags_on_save
    send :include, Sanitizing
  end

end