class Wishlist < ActiveRecord::Base
  # Relationships -------------------------------------------------------------
  belongs_to :item
  belongs_to :member
  
  # Attributes ----------------------------------------------------------------
  attr_accessible :item_name, :priority, :note, :member_id
  
  # Validations ---------------------------------------------------------------
  validates_format_of :priority, :with => /^(normal|best in slot|situational|rot)/, :allow_nil => true
  
  # Callbacks -----------------------------------------------------------------
  
  # Class Methods -------------------------------------------------------------
  
  # Instance Methods ----------------------------------------------------------
  def item_name
    self.item.name unless self.item_id.nil?
  end
  def item_name=(value)
    item = Item.find_by_name(value)
    self.item = item unless item.nil?
  end
  
  private
    def validate
      errors.add(:item_name, 'is invalid') if self.item_id.nil? or self.item.name.empty?
    end
end

class Wishlist < ActiveRecord::Base
  PRIORITIES = ['normal','best in slot','situational','rot']
  
  # Relationships -------------------------------------------------------------
  belongs_to :item
  belongs_to :member
  
  # Attributes ----------------------------------------------------------------
  attr_accessible :item_name, :priority, :note, :member_id
  
  # Validations ---------------------------------------------------------------
  validates_inclusion_of :priority, :in => PRIORITIES, :message => "{{value}} is not a valid entry type", :allow_nil => true
  
  # Callbacks -----------------------------------------------------------------
  
  # Class Methods -------------------------------------------------------------
  
  # Instance Methods ----------------------------------------------------------
  def item_name
    self.item.name unless self.item_id.nil?
  end
  def item_name=(value)
    item = Item.find_or_create_by_name(value)
    self.item = item unless item.nil?
  end
  
  private
    def validate
      errors.add(:item_name, 'is invalid') if self.item_id.nil? or self.item.name.empty?
    end
end

Change validation for type from format_of to inclusion_of; For now, if the item isn't found we're gonna create it. This could lead to all kinds of invalid Item entries being created.
Change validation for type from format_of to inclusion_of; For now, if the item isn't found we're gonna create it. This could lead to all kinds of invalid Item entries being created.
