Sha256: 3691feddd84e65a65e285656c195cc724789dbfde2788412ab855c2e58677d57

Contents?: true

Size: 660 Bytes

Versions: 13

Compression:

Stored size: 660 Bytes

Contents

class ListItem < ActiveRecord::Base
  include Concerns::Model::BaseListItem
  
  attr_accessible :list_id, :thing, :thing_type, :thing_id, :best, :stars
  
  has_many :user_list_items, dependent: :destroy
  
  validates :thing_id, presence: true, uniqueness: { scope: [:list_id, :thing_type] }
  validate :type_equals_thing_type_of_list
  
  acts_as_list scope: :list
  
  private
  
  def type_equals_thing_type_of_list
    return unless list_thing_type = list.try(:thing_type)

    unless list_thing_type == thing_type
      errors[:thing_type] << I18n.t('activerecord.errors.models.list_item.attributes.thing_type.no_valid_type_for_list') 
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
voluntary-0.7.1 app/models/list_item.rb
voluntary-0.7.0 app/models/list_item.rb
voluntary-0.6.0 app/models/list_item.rb
voluntary-0.5.2 app/models/list_item.rb
voluntary-0.5.1 app/models/list_item.rb
voluntary-0.5.0 app/models/list_item.rb
voluntary-0.4.0 app/models/list_item.rb
voluntary-0.3.0 app/models/list_item.rb
voluntary-0.2.4 app/models/list_item.rb
voluntary-0.2.3 app/models/list_item.rb
voluntary-0.2.2 app/models/list_item.rb
voluntary-0.2.1 app/models/list_item.rb
voluntary-0.2.0 app/models/list_item.rb