aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/app/models
diff options
context:
space:
mode:
authorJason Lee <huacnlee@gmail.com>2018-02-01 23:49:25 +0800
committerJason Lee <huacnlee@gmail.com>2018-02-01 23:49:25 +0800
commit69ae9fe6b508acdf5bdfc64c5baae70bce15fad6 (patch)
treebfa0e3f929b0a22cfeb1f748d4d7a37d0a74e9d9 /activestorage/app/models
parent4f0eb1ccd9652118b05d42f152adaa4df7dc3388 (diff)
downloadrails-69ae9fe6b508acdf5bdfc64c5baae70bce15fad6.tar.gz
rails-69ae9fe6b508acdf5bdfc64c5baae70bce15fad6.tar.bz2
rails-69ae9fe6b508acdf5bdfc64c5baae70bce15fad6.zip
Allow `ActiveStorage::Blob#service_url` to pass addition options to `service.url`.
Because there have some service needs more parameters for file URL: https://www.alibabacloud.com/help/doc-detail/44687.htm ```rb class AliyunService < Service def url(key, options = {}) image_process = options[:oss_process] || "image/resize,w_800" "http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=#{image_process}" end end ``` Use case: ```erb <%= image_tag @user.avatar.service_url(oss_process: "image/resize,m_fill,h_100,w_100" %> ```
Diffstat (limited to 'activestorage/app/models')
-rw-r--r--activestorage/app/models/active_storage/blob.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb
index 7067c58259..886fbb31e3 100644
--- a/activestorage/app/models/active_storage/blob.rb
+++ b/activestorage/app/models/active_storage/blob.rb
@@ -109,8 +109,9 @@ class ActiveStorage::Blob < ActiveRecord::Base
# with users. Instead, the +service_url+ should only be exposed as a redirect from a stable, possibly authenticated URL.
# Hiding the +service_url+ behind a redirect also gives you the power to change services without updating all URLs. And
# it allows permanent URLs that redirect to the +service_url+ to be cached in the view.
- def service_url(expires_in: service.url_expires_in, disposition: :inline, filename: self.filename)
- service.url key, expires_in: expires_in, disposition: forcibly_serve_as_binary? ? :attachment : disposition, filename: filename, content_type: content_type
+ def service_url(expires_in: service.url_expires_in, disposition: :inline, filename: self.filename, **options)
+ service.url key, expires_in: expires_in, filename: filename, content_type: content_type,
+ disposition: forcibly_serve_as_binary? ? :attachment : disposition, **options
end
# Returns a URL that can be used to directly upload a file for this blob on the service. This URL is intended to be