Giter Club home page Giter Club logo

administrate-field-active_storage's Introduction

Administrate::Field::ActiveStorage

rails

Things To Know:

  • to preview pdf files you need to install mupdf or Poppler.
  • to preview video files you need to install ffmpeg.

How To Use:

Add administrate-field-active_storage to your Gemfile:

gem 'administrate-field-active_storage'

Install:

$ bundle install

has_one_attached:

assuming your modelname is Model and field name is attachment

class ModelDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    attachment: Field::ActiveStorage,
  }
# ...

Then add :attachment to FORM_ATTRIBUTES and SHOW_PAGE_ATTRIBUTES. currently adding :attachment COLLECTION_ATTRIBUTES will work but will probably look too big.

has_many_attached:

assuming your modelname is Model and field name is attachments the processs is identical the only issue is that the form field isn't being permitted, in order to permit it we apply the following method to the dashboard:

class ModelDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    attachments: Field::ActiveStorage,
  }

  # ...
  FORM_ATTRIBUTES = {
    #...
    :attachments
  }

  # permitted for has_many_attached
  def permitted_attributes
    super + [:attachments => []]
  end

i know it is not ideal, if you have a workaround please submit a PR

url_only

only the following needs to change in order for the field to be url_only

class ModelDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    attachments: Field::ActiveStorage.with_options({url_only: true}),
    # ...
  }
  # ...
end

Things To Do:

  • upload single file
  • adding image support through url_for to support 3rd party cloud storage
  • use html 5 video element for video files
  • use html audio element for audio files
  • download link to other files
  • preview videos
  • preview pdfs
  • upload multiple files
  • find a way to delete attachments
  • preview office files as pictures

Contribution guide:

  1. contributers are welcome (code, suggestions, and bugs).

  2. please document your code.

  3. add your name to the contribute.md.

    please note that this is my first gem :) i might have gotten some stuff wrong PR's are always welcome


Based on the Administrate::Field::Image template, and inspired by Administrate::Field::Paperclip.

administrate-field-active_storage's People

Contributors

acrogenesis avatar benmorganio avatar c-lliope avatar dreamersoul avatar huhn511 avatar nickcharlton avatar pedantic-git avatar pushcx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.