Class: List
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- List
- Defined in:
- app/models/list.rb
Class Method Summary collapse
-
.find_or_create_by_params(params) ⇒ Object
pusherable “#Rails.env_channel”.
Class Method Details
.find_or_create_by_params(params) ⇒ Object
pusherable “#Rails.env_channel”
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/list.rb', line 12 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 |