i’m not sure if this is the right place for this but it its an
activerecord issue so hopefully it is.
anyway when ever i try and save a model it come back as true but when i
find the object again it hasn’t changed.
For example:
p = Post.find 1
p.title.capitalize!
p.save # Returns true but doesn’t actually save
the logger outputs the following when i save it
D, [2011-05-17T18:33:55.786908 #5595] DEBUG – : SQL (0.2ms) BEGIN
D, [2011-05-17T18:33:55.787576 #5595] DEBUG – : SQL (0.1ms) COMMIT
=> true
Any reason for this?
Thanks, James.
which rails?
try (in console)
p = Post.find 1
p.title.capitalize!
p.title
p.save
p.errors.inspect
tom
On May 17, 2011, at 19:45 , james b. wrote:
p.save # Returns true but doesn’t actually save
–
Posted via http://www.ruby-forum.com/.
–
You received this message because you are subscribed to the Google G. “Ruby
on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
–
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
Thanks very much i had been pondering on this for a while
Final Solution:
p.title = p.title.capitalize
instead of
p.title.capitalize!
On 17 May 2011, at 18:45, “james b.” [email protected] wrote:
p.save # Returns true but doesn’t actually save
Inplace modification of attributes confuses the change tracking in ar -
either don’t do it (ie p.title = p.title.capitalize) or call the
title_will_change! method after you do
Fred
or p.update_attribute(:title, p.title.capitalize) and without p.save
or if you want to capitalize in your model (when saving), you could do
that with before filter
before_save do |row|
row.title = row.title.capitalize unless row.title.blank?
end
tom
On May 17, 2011, at 22:17 , james b. wrote:
–
You received this message because you are subscribed to the Google G. “Ruby
on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
–
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache