Sha256: 354b7f7ec512c732ad81112944dc7705fc2ce28a9eb625d9d7dac8f48218327f

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 Bytes

Contents

class Topic
  include ActiveModel::Validations
  include ActiveModel::Validations::Callbacks

  def self._validates_default_keys
    super | [ :message ]
  end

  attr_accessor :title, :author_name, :content, :approved
  attr_accessor :after_validation_performed

  after_validation :perform_after_validation

  def initialize(attributes = {})
    attributes.each do |key, value|
      send "#{key}=", value
    end
  end

  def condition_is_true
    true
  end

  def condition_is_true_but_its_not
    false
  end

  def perform_after_validation
    self.after_validation_performed = true
  end

  def my_validation
    errors.add :title, "is missing" unless title
  end

  def my_validation_with_arg(attr)
    errors.add attr, "is missing" unless send(attr)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mass_assignment_with_multiple_roles-0.0.1 test/models/topic.rb