raybaxter (owner)

Fork Of

Revisions

  • 6f913a andrewc... Fri Apr 10 12:34:13 -0700 2009
gist: 93382 Download_button fork
public
Public Clone URL: git://gist.github.com/93382.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
# known to break on any column named 'type'
  def self.create_or_update(options = {})
    id = options.delete(:id)
    record = find_by_id(id) || new
    record.id = id
    
    options.each_pair do |attr, value|
      record.send(attr.to_s + '=', value)
    end
    record.save!
  
    record
  end