Forum: Ruby on Rails how to appned some string with file name

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2009-02-17 13:42
Dear all.
using this below code i get file name of blob
image = params[:image][:blob]
          puts image.methods
          image_name = image.original_filename
it gives me
=> rose.jpg
actually i want to append some string with it.how can i do it.pls help.
example => rose_big.jpg


Thanks
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-02-17 14:22
(Received via mailing list)
>> string = "rose.jpg"
=> "rose.jpg"
>> modified = string[0..-5] + "_big" + string[-4..-1]
=> "rose_big.jpg"

you might wannt to check for the "." in that string and cut it there.
check out some ruby basics for string manipulation.
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2009-02-17 14:53
(Received via mailing list)
On Tue, Feb 17, 2009 at 4:42 AM, Newb Newb
<rails-mailing-list@andreas-s.net
> wrote:

>
Hi, here's another option using the File class:

filename = File.basename( filename, ".jpg" )  + "_what_ever_you_want
+ File.basename( filename )

Good luck,

-Conrad
This topic is locked and can not be replied to.