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
Regular expression for image types
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
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
To get url of attachment.
# File app/models/attachment.rb, line 51 def url(style = :original) attachment && attachment.url(style) end