Sha256: 9cd016d9b3beb983943fd335098f7d2d24873f306726b26c4d64ff76871a1d40
Contents?: true
Size: 1.04 KB
Versions: 13
Compression:
Stored size: 1.04 KB
Contents
class List < ActiveRecord::Base attr_accessible :adjective, :topic, :scope, :thing_type, :negative_adjective has_many :items, class_name: 'ListItem', dependent: :destroy validates :adjective, presence: true validates :topic, presence: true, uniqueness: { scope: [:adjective, :scope] } validates :scope, presence: true #pusherable "#{Rails.env}_channel" def self.find_or_create_by_params(params) attributes = (params[:user_list_item] || params[:list_item] || params).clone attributes.symbolize_keys! unless params.is_a?(ActiveSupport::HashWithIndifferentAccess) if attributes[:list_id].present? then List.find(attributes[:list_id]) elsif attributes[:adjective].present? list = List.new attributes.each {|param, value| attributes.delete(param) unless list.respond_to?(param) } List.where(attributes).first || List.create(attributes) elsif attributes[:topic].present? begin attributes[:topic].classify.constantize.list rescue NameError end end end end
Version data entries
13 entries across 13 versions & 1 rubygems