Rails: saving a string on an object -- syntax problem?

Posted by Veep on Stack Overflow See other posts from Stack Overflow or by Veep
Published on 2010-03-20T19:25:41Z Indexed on 2010/03/20 19:31 UTC
Read the original article Hit count: 135

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.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rails