Skip to content

Latest commit

 

History

History
59 lines (36 loc) · 1.83 KB

paperclip.md

File metadata and controls

59 lines (36 loc) · 1.83 KB

Install and Configure Paperclip

Install and configure following the Paperclip installation instructions

Configure migration to use Paperclip

Configure the migration to use Paperclip for a specific field, in the example bellow Paperclip will be used to upload a file to image attribute.

  create_table :photos do |t|
    t.attachment :image
    t.string :title
    t.references :person, index: true
    t.timestamps
  end

Configure model to use Paperclip

Configure the model to use Paperclip for a specific field, in the example bellow Paperclip will be used to upload a file to image attribute.

class Photo < ActiveRecord::Base

  has_attached_file :image, styles: { medium: '640x480>', thumb: '160x120>'  }, default_url: 'missing.png'

  validates_attachment :image, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] }

end

Configure Presenter to use admin_previewable_input

In your presenter use the admin_previewable_file input to handle the field configures with paperclip.

  field :image,
    actions: [:new, :edit, :show],
    as: :admin_previewable_file

Example of the rendered edit form:

Upload With paperclip

Full functional Sample Application

Sourcecode

Online Sample