I''m trying this in the save method of an ActiveRecord object:
def save
f = self.file
self.file_extension = f.match(/\.(.+?)$/)[1] if self.file # returns
entire file name
self.file_extension = f.scan(/\.(.+?)$/)[0][0] if self.file #
returns entire file name
self.file_extension = f[f.rindex(''.'')+1, f.length] #
works!
super
if self.file
FileUtils.cp(self.file, self.file_path)
FileUtils.chmod(FILE_MODE, self.file_path)
end
end
As you can see by my comments, the first two return the entire file
name. I''ve done the same two equivalent lines in script/console and
they
both return the extension I''m looking for. Any idea why they behave
differently in ActiveRecord?
Thanks,
Joe
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---