In a _form, I have a field to upload files. What I am trying to do is check if the file contains a dangerous extension.
In my case, I return an error message if the extension is one of the following: . 'bat'. 'with'. 'exe'. 'src',. 'cmd'
So I did this:
def suspitious_attachment
if ends_with? '.bat', '.com', '.exe', '.src', '.cmd'
errors.add(:base, I18n.t('errors.messages.suspitious_attachment', :value => attachments.split(".").last))
end
end
But it is not a good idea, a file can have multiple dot in the name.
So I would like to get the last 4 letters of the name.
I'm not able to do this, can you help me?
Sorry for my English.