开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜