Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude the "." from a file extension in Rails

How do I the dot when getting the file extension name in rails?

Right now I'm using File.extname but it's keeping the "." before giving me the name

like image 862
Jon Avatar asked Dec 11 '22 14:12

Jon


1 Answers

Would this work for you?

File.extname('something.jpg').delete('.') #=> 'jpg'

You could even wrap it up in a helper:

def file_extension(filename)
  File.extname(filename).delete('.')
end

file_extension('something.jpg') #=> 'jpg'
like image 167
Charles Caldwell Avatar answered Dec 29 '22 02:12

Charles Caldwell