Module: DynamicImage::Routing

Defined in:
lib/dynamic_image/routing.rb

Overview

DynamicImage Routing

Extends ActionDispatch::Routing::Mapper and provides a shortcut for defining routes for DynamicImage::Controller.

Instance Method Summary collapse

Instance Method Details

#image_resources(resource_name, options = {}) ⇒ void

This method returns an undefined value.

Declares an image resource, routing show along with the uncropped, original and download member actions.

The default path includes the digest and an optional size. Pass :path to change it if the resource collides with a directory in public.

Examples:

image_resources :avatars

Keeping clear of public/images

image_resources :images, path: "dynamic_images/:digest(/:size)"

Parameters:

  • resource_name (Symbol, String)

    the resource

  • options (Hash) (defaults to: {})

    options passed to resources, merged over the defaults



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dynamic_image/routing.rb', line 23

def image_resources(resource_name, options = {})
  options = {
    path: "#{resource_name}/:digest(/:size)",
    constraints: { size: /\d+x\d+/ },
    only: %i[show]
  }.merge(options)

  resources resource_name, **options do
    get :uncropped, on: :member
    get :original, on: :member
    get :download, on: :member
  end
end