class Attachment

Schema Information

Table name: attachments

id                      :integer          not null, primary key
resource_id             :integer
resource_type           :string(255)
attachment_file_name    :string(255)
attachment_content_type :string(255)
attachment_file_size    :integer
attachment_updated_at   :datetime
university_id              :integer
created_at              :datetime
updated_at              :datetime

Constants

IMAGE_REGEX

Regular expression for image types

Public Instance Methods

has_access_to?(user) click to toggle source

Setup access right for user.

# File app/models/attachment.rb, line 35
def has_access_to?(user)
  return true if user.admin?
  case resource_type
    when 'Comment'
      user.groups.where(id: resource.commentable.group).exists?
    when 'Message'
      user.conversations.exists?(id: resource.chat_conversation)
  end
end
image?() click to toggle source

To check attachment content tpye with types of images.

# File app/models/attachment.rb, line 46
def image?
  attachment && attachment.content_type.match(IMAGE_REGEX)
end
url(style = :original) click to toggle source

To get url of attachment.

# File app/models/attachment.rb, line 51
def url(style = :original)
  attachment && attachment.url(style)
end