Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/update_or_create/activerecord.rb

Class Method Summary collapse

Class Method Details

.update_or_create(attributes_array) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/update_or_create/activerecord.rb', line 6

def update_or_create(attributes_array)
				attributes_array.each do |attributes|
begin
	first = self.find(attributes[:id])
rescue
end
if first.nil?
	self.new(attributes).save
else
       if attributes['delete record !!!'] == true
         first.destroy
       else
			first.attributes = attributes
			first.save
       end
end
				end
end