views:

26

answers:

1

Hey there, I am trying to write a simple function to clean a filename string and update the object. When I save a test string it works, but when I try to save the string variable I've created, nothing happens. But when I return the string, the output seems to be correct! What am I missing?

 def clean_filename    
   clean_name = filename
   clean_name.gsub! /^.*(\\|\/)/, ''
   clean_name.gsub! /[^A-Za-z0-9\.\-]/, '_'
   clean_name.gsub!(/\_+/, ' ')
   #update_attribute(:filename, "test") #<-- correctly sets filename to test
   #update_attribute(:filename, clean_name) #<-- no effect????? WTF
   #return clean_name <-- seems to returns the correct string
 end

Thank you very much.

A: 

Is the update only going through if the object ID has changed? I think it is reasonable to update the slot only when the object itself has changed.

Have you ever tried to use gsub instead of gsub!, so that the object ID changes?

mliebelt