Skip to content

Commit

Permalink
docs(example project): the example project now includes an example fo…
Browse files Browse the repository at this point in the history
…r destroy_path
  • Loading branch information
Dreamersoul committed Dec 21, 2018
1 parent fa127c5 commit 9124d55
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 71 deletions.
126 changes: 64 additions & 62 deletions example-project/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
PATH
remote: ..
specs:
administrate-field-active_storage (0.1.3)
administrate-field-active_storage (0.1.5)
administrate (>= 0.2.0.rc1)
rails (>= 5.2)

GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.1)
actionpack (= 5.2.1)
actioncable (5.2.2)
actionpack (= 5.2.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.1)
actionpack (= 5.2.1)
actionview (= 5.2.1)
activejob (= 5.2.1)
actionmailer (5.2.2)
actionpack (= 5.2.2)
actionview (= 5.2.2)
activejob (= 5.2.2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.1)
actionview (= 5.2.1)
activesupport (= 5.2.1)
actionpack (5.2.2)
actionview (= 5.2.2)
activesupport (= 5.2.2)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.1)
activesupport (= 5.2.1)
actionview (5.2.2)
activesupport (= 5.2.2)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.1)
activesupport (= 5.2.1)
activejob (5.2.2)
activesupport (= 5.2.2)
globalid (>= 0.3.6)
activemodel (5.2.1)
activesupport (= 5.2.1)
activerecord (5.2.1)
activemodel (= 5.2.1)
activesupport (= 5.2.1)
activemodel (5.2.2)
activesupport (= 5.2.2)
activerecord (5.2.2)
activemodel (= 5.2.2)
activesupport (= 5.2.2)
arel (>= 9.0)
activestorage (5.2.1)
actionpack (= 5.2.1)
activerecord (= 5.2.1)
activestorage (5.2.2)
actionpack (= 5.2.2)
activerecord (= 5.2.2)
marcel (~> 0.3.1)
activesupport (5.2.1)
activesupport (5.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
Expand All @@ -65,20 +65,21 @@ GEM
archive-zip (0.11.0)
io-like (~> 0.3.0)
arel (9.0.0)
autoprefixer-rails (9.1.4)
autoprefixer-rails (9.4.3)
execjs
bindex (0.5.0)
bootsnap (1.3.2)
msgpack (~> 1.0)
builder (3.2.3)
byebug (10.0.2)
capybara (3.9.0)
capybara (3.12.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
xpath (~> 3.1)
regexp_parser (~> 1.2)
xpath (~> 3.2)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
chromedriver-helper (2.1.0)
Expand All @@ -91,19 +92,19 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
concurrent-ruby (1.1.4)
crass (1.0.4)
datetime_picker_rails (0.0.7)
momentjs-rails (>= 2.8.1)
erubi (1.7.1)
erubi (1.8.0)
execjs (2.7.0)
ffi (1.9.25)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (1.1.0)
i18n (1.3.0)
concurrent-ruby (~> 1.0)
io-like (0.3.0)
jbuilder (2.7.0)
jbuilder (2.8.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
jquery-rails (4.3.3)
Expand All @@ -126,61 +127,62 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.2.2)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.0)
mimemagic (0.3.2)
method_source (0.9.2)
mimemagic (0.3.3)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
mini_portile2 (2.4.0)
minitest (5.11.3)
momentjs-rails (2.20.1)
railties (>= 3.1)
msgpack (1.2.4)
multi_json (1.13.1)
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
nokogiri (1.9.1)
mini_portile2 (~> 2.4.0)
public_suffix (3.0.3)
puma (3.12.0)
rack (2.0.5)
rack (2.0.6)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.1)
actioncable (= 5.2.1)
actionmailer (= 5.2.1)
actionpack (= 5.2.1)
actionview (= 5.2.1)
activejob (= 5.2.1)
activemodel (= 5.2.1)
activerecord (= 5.2.1)
activestorage (= 5.2.1)
activesupport (= 5.2.1)
rails (5.2.2)
actioncable (= 5.2.2)
actionmailer (= 5.2.2)
actionpack (= 5.2.2)
actionview (= 5.2.2)
activejob (= 5.2.2)
activemodel (= 5.2.2)
activerecord (= 5.2.2)
activestorage (= 5.2.2)
activesupport (= 5.2.2)
bundler (>= 1.3.0)
railties (= 5.2.1)
railties (= 5.2.2)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.1)
actionpack (= 5.2.1)
activesupport (= 5.2.1)
railties (5.2.2)
actionpack (= 5.2.2)
activesupport (= 5.2.2)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rake (12.3.1)
rake (12.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rb-inotify (0.10.0)
ffi (~> 1.0)
regexp_parser (1.3.0)
ruby_dep (1.5.0)
rubyzip (1.2.2)
sass (3.6.0)
sass (3.7.2)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand All @@ -191,8 +193,8 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
selectize-rails (0.12.5)
selenium-webdriver (3.14.1)
selectize-rails (0.12.6)
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
spring (2.0.2)
Expand All @@ -208,15 +210,15 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
thor (0.20.0)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.8)
tilt (2.0.9)
turbolinks (5.2.0)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.19)
uglifier (4.1.20)
execjs (>= 0.3.0, < 3)
web-console (3.7.0)
actionview (>= 5.0)
Expand All @@ -226,7 +228,7 @@ GEM
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
xpath (3.1.0)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
Expand Down
7 changes: 7 additions & 0 deletions example-project/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class UsersController < ApplicationController
def remove_attachment
attachment = ActiveStorage::Attachment.find(params[:attachment_id])
attachment.purge
redirect_back(fallback_location: "/")
end
end
13 changes: 9 additions & 4 deletions example-project/app/dashboards/user_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UserDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
id: Field::Number,
name: Field::String,
avatar: Field::ActiveStorage,
avatars: Field::ActiveStorage.with_options({:destroy_path => :custom_active_record_remove_path}),
created_at: Field::DateTime,
updated_at: Field::DateTime,
}.freeze
Expand All @@ -23,15 +23,15 @@ class UserDashboard < Administrate::BaseDashboard
COLLECTION_ATTRIBUTES = [
:id,
:name,
:avatar,
:avatars,
].freeze

# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = [
:id,
:name,
:avatar,
:avatars,
:created_at,
:updated_at,
].freeze
Expand All @@ -41,7 +41,7 @@ class UserDashboard < Administrate::BaseDashboard
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [
:name,
:avatar,
:avatars,
].freeze

# Overwrite this method to customize how users are displayed
Expand All @@ -50,4 +50,9 @@ class UserDashboard < Administrate::BaseDashboard
# def display_resource(user)
# "User ##{user.id}"
# end

# permitted for has_many_attached
def permitted_attributes
super + [:avatars => []]
end
end
2 changes: 1 addition & 1 deletion example-project/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class User < ApplicationRecord
has_one_attached :avatar
has_many_attached :avatars
end
7 changes: 4 additions & 3 deletions example-project/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Rails.application.routes.draw do
namespace :admin do
resources :users
resources :users

root to: "users#index"
end
root to: "users#index"
end
delete "custom_active_record_remove", to: 'users#remove_avatar'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
def change
create_table :active_storage_blobs do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.bigint :byte_size, null: false
t.string :checksum, null: false
t.datetime :created_at, null: false

t.index [ :key ], unique: true
end

create_table :active_storage_attachments do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false
t.references :blob, null: false

t.datetime :created_at, null: false

t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
end
end
end
23 changes: 22 additions & 1 deletion example-project/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,28 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_10_13_145025) do
ActiveRecord::Schema.define(version: 2018_12_21_134334) do

create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.integer "record_id", null: false
t.integer "blob_id", null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end

create_table "active_storage_blobs", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.bigint "byte_size", null: false
t.string "checksum", null: false
t.datetime "created_at", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end

create_table "users", force: :cascade do |t|
t.string "name"
Expand Down

0 comments on commit 9124d55

Please sign in to comment.