LoginSignup
11
9

More than 5 years have passed since last update.

Refileで画像のURLをカスタマイズしたい

Last updated at Posted at 2015-09-20

※今回使用したバージョン 0.6.1

デフォルトではこんな感じです。

Refile.attachment_url(Video.first, :image, :fill, 200, 200, format: 'jpg')
# => "/attachments/<signaturetoken>/<backend>/fill/200/200/:image_id/:image_filename.jpg"

パスを変えたい

仮に/attachmentsではなくimagesにするなら

config/initializers/refile.rb

Refile.mount_point = 'images'

とすれば

Refile.attachment_url(Video.first, :image, :fill, 200, 200, format: 'jpg')
# => "/images/<signature>/store/fill/200/200/:image_id/:image_filename.jpg"

になり、画像サーバがマウントされるのもそこになります。

ホスト部やスキームを指定したい

CloudFrontなどのCDNを使う場合やSSLページで使うためにhttps://あるいは//からはじめたいことがあります。

config/initializers/refile.rb

Refile.cdn_host = Rails.application.secrets.cdn_host

config/secrets.yml

development:
   cdn_host: <%= ENV["CDN_HOST"] %>

のような感じにしておくと

Refile.attachment_url(Video.first, :image, :fill, 200, 200, format: 'jpg')
# => "//your-cdn-host.com/attachments/<signature>/store/fill/200/200/:image_id/:image_filename.jpg"

となります。

11
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
9