Skip to content

Instantly share code, notes, and snippets.

@hidenba
Created March 10, 2011 08:47
Show Gist options
  • Save hidenba/863778 to your computer and use it in GitHub Desktop.
Save hidenba/863778 to your computer and use it in GitHub Desktop.
# changedの振る舞い
t = Event.new
param = {:year=>2000, :month=>'', :day=>nil}
t.attributes = param
t.changed? #=> true
t.year_changed? #=> true
t.month_changed? #=> false
t.day_changed? #=> false
t.changes #=> {"year"=>[nil, 2000]}
#============================================
Event.all.each do |event|
param = params.detect {|id,val| id == event.id}.last
event.attributes = param
event.save! if event.changed?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment