module Shrine::Plugins::DefaultUrl

  1. lib/shrine/plugins/default_url.rb

The default_url plugin allows setting the URL which will be returned when the attachment is missing.

plugin :default_url

Attacher.default_url do |options|
  "/#{name}/missing.jpg"
end

Attacher#url returns the default URL when attachment is missing. Any passed in URL options will be present in the options hash.

attacher.url #=> "/avatar/missing.jpg"
# or
user.avatar_url #=> "/avatar/missing.jpg"

The default URL block is evaluated in the context of an instance of Shrine::Attacher.

Attacher.default_url do |options|
  self #=> #<Shrine::Attacher>

  name   #=> :avatar
  record #=> #<User>
end

Methods

Public Class

  1. configure

Public Class methods

configure (uploader, &block)
[show source]
# File lib/shrine/plugins/default_url.rb, line 29
def self.configure(uploader, &block)
  if block
    uploader.opts[:default_url] = block
    Shrine.deprecation("Passing a block to default_url plugin is deprecated and will probably be removed in future versions of Shrine. Use `Attacher.default_url { ... }` instead.")
  end
end