Rails. Regex Help to determine if the doc type is a Document
I'm trying to create a regex that will return true when the content type is: ap开发者_Go百科plication/msword or text/rtf)
I have the following:
def istext?
if !(attachment.content_type =~ %r{^(application|(x-)?application)/(msword|rtf)$})
return false
else
return true
end
end
Any smart ideas on how to get this method to return true for application/msword or text/rtf and false for anything else?
Thanks
Why use a regex?
def istext?
%w(application/msword text/rtf).include?(attachment.content_type)
end
精彩评论