Class: Paper
- Defined in:
- app/models/media/paper.rb
Overview
Schema Information
Table name: assets
id :integer not null, primary key
data_file_name :string(255) not null
data_content_type :string(255)
data_file_size :integer
assetable_id :integer not null
assetable_type :string(25) not null
type :string(25)
guid :string(255)
locale :integer default(0)
user_id :integer
sort_order :integer default(0)
width :integer
height :integer
created_at :datetime
updated_at :datetime
public_token :string(255)
Instance Method Summary collapse
- #apifile ⇒ Object
- #as_json(options = nil) ⇒ Object
- #assetable? ⇒ Boolean
- #sync_file ⇒ Object
- #thumb_url ⇒ Object
- #uploader_destroy(params, request = nil) ⇒ Object
- #url(*args) ⇒ Object
Methods inherited from Asset
find_klass, #uri, #x_accel_url
Instance Method Details
#apifile ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/media/paper.rb', line 44 def apifile @apifile ||= TranslationCms::Api::Paper.new( _satellite_id: Settings.satellite_id, order_id: assetable_id, filename: filename, content_type: content_type, size: size, remote_asset_id: id ) end |
#as_json(options = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'app/models/media/paper.rb', line 78 def as_json( = nil) = { root: 'asset', only: [:id, :guid, :assetable_id, :assetable_type, :user_id, :public_token], methods: [:filename, :url, :thumb_url, :size, :content_type, :order_id, :remote_asset_id] }.merge( || {}) super() end |
#assetable? ⇒ Boolean
40 41 42 |
# File 'app/models/media/paper.rb', line 40 def assetable? assetable_id.to_i > 0 end |
#sync_file ⇒ Object
63 64 65 |
# File 'app/models/media/paper.rb', line 63 def sync_file apifile.save end |
#thumb_url ⇒ Object
36 37 38 |
# File 'app/models/media/paper.rb', line 36 def thumb_url '/assets/defaults/attachment.png' end |
#uploader_destroy(params, request = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/media/paper.rb', line 67 def uploader_destroy(params, request = nil) user = request.env['warden'].user(:account) ability = Ability.new(user) if ability.can? :delete, self super else errors.add(:id, :access_denied) end end |
#url(*args) ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/models/media/paper.rb', line 55 def url(*args) if ENV['AWS_ENABLE'] == '1' "/downloads/#{type.downcase}/#{id}/#{data_file_name}" else super(*args) end end |