ファイル名文字列を消去してオブジェクトを更新する単純な関数を作成しようとしています。テスト文字列を保存すると機能しますが、作成した文字列変数を保存しようとしても何も起こりません。しかし、文字列を返すと、出力は正しいようです! 私は何が欠けていますか?
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
どうもありがとうございました。