Нет запросов к базе данных, вот простой пример использования Rails 3.1.1 в консоли:
> s = Shop.first
=> #<Shop id: 1, name: "Ben", address: "paris", latitude:
> 48.856614, longitude: 2.3522219, gmaps: true, created_at: "2011-10-13 13:17:24", updated_at: "2011-10-13 13:17:24"> ruby-1.9.2-p290 :003 >
> s.name = "Ben" => "Ben"
> s.save
=> true
> s.updated_at
=> Thu, 13 Oct 2011 13:17:24 UTC +00:00
> s.update_attribute(:name, "Ben")
=> true
> s.updated_at
=> Thu, 13 Oct 2011 13:17:24 UTC +00:00
> s.update_attributes({:name => "Ben"})
=> true
> s.updated_at
=> Thu, 13 Oct 2011 13:17:24 UTC +00:00
> s.name = "Ben"
=> "Ben"
> s.save!
> s.updated_at
=> Thu, 13 Oct 2011 13:17:24 UTC +00:00
Edit:
rails profiler 's = Shop.first; s.name = "Ben"; s.save;' 's = Shop.first; s.name =
Loaded suite script/rails
Started
ProfilerTest#test_s_shop_first_s_name_ben_s_save (78 ms warmup)
process_time: 5 ms
ProfilerTest#test_s_shop_first_s_name_ben_s_save_if_s_changed (1 ms warmup)
process_time: 2 ms
Finished in 2.597531 seconds.
Так что быстрее с if changed?
.