From 03d81f6d6a9db3722559fee2bcd741dee2c2ec75 Mon Sep 17 00:00:00 2001 From: David Stump Date: Wed, 25 Mar 2015 11:00:35 -0400 Subject: [PATCH 1/2] Namespaces Asset model to avoid collisions with existing projects --- app/models/{asset.rb => wysi_html_five_asset.rb} | 3 +-- ...6182611_create_active_admin_wysihtml5_assets.rb | 2 +- ...0130124143200_add_magic_attributes_to_assets.rb | 14 +++++++------- lib/active_admin/wysihtml5/admin/assets.rb | 7 +++---- 4 files changed, 12 insertions(+), 14 deletions(-) rename app/models/{asset.rb => wysi_html_five_asset.rb} (93%) diff --git a/app/models/asset.rb b/app/models/wysi_html_five_asset.rb similarity index 93% rename from app/models/asset.rb rename to app/models/wysi_html_five_asset.rb index 5b19bbe..3b240e0 100644 --- a/app/models/asset.rb +++ b/app/models/wysi_html_five_asset.rb @@ -1,4 +1,4 @@ -class Asset < ActiveRecord::Base +class WysiHtmlFiveAsset < ActiveRecord::Base image_accessor :storage def percentage_thumb_url(size) @@ -27,4 +27,3 @@ def as_json(options = {}) } end end - diff --git a/db/migrate/20120816182611_create_active_admin_wysihtml5_assets.rb b/db/migrate/20120816182611_create_active_admin_wysihtml5_assets.rb index 8370fd9..510dd1b 100644 --- a/db/migrate/20120816182611_create_active_admin_wysihtml5_assets.rb +++ b/db/migrate/20120816182611_create_active_admin_wysihtml5_assets.rb @@ -1,7 +1,7 @@ class CreateActiveAdminWysihtml5Assets < ActiveRecord::Migration def change - create_table :assets do |t| + create_table :wysi_html_five_assets do |t| t.string :storage_uid t.string :storage_name t.timestamps diff --git a/db/migrate/20130124143200_add_magic_attributes_to_assets.rb b/db/migrate/20130124143200_add_magic_attributes_to_assets.rb index e48a01a..5fd5325 100644 --- a/db/migrate/20130124143200_add_magic_attributes_to_assets.rb +++ b/db/migrate/20130124143200_add_magic_attributes_to_assets.rb @@ -1,11 +1,11 @@ class AddMagicAttributesToAssets < ActiveRecord::Migration def change - add_column :assets, :storage_width, :integer - add_column :assets, :storage_height, :integer - add_column :assets, :storage_aspect_ratio, :float - add_column :assets, :storage_depth, :integer - add_column :assets, :storage_format, :string - add_column :assets, :storage_mime_type, :string - add_column :assets, :storage_size, :string + add_column :wysi_html_five_assets, :storage_width, :integer + add_column :wysi_html_five_assets, :storage_height, :integer + add_column :wysi_html_five_assets, :storage_aspect_ratio, :float + add_column :wysi_html_five_assets, :storage_depth, :integer + add_column :wysi_html_five_assets, :storage_format, :string + add_column :wysi_html_five_assets, :storage_mime_type, :string + add_column :wysi_html_five_assets, :storage_size, :string end end diff --git a/lib/active_admin/wysihtml5/admin/assets.rb b/lib/active_admin/wysihtml5/admin/assets.rb index 8d6ea08..74bd05c 100644 --- a/lib/active_admin/wysihtml5/admin/assets.rb +++ b/lib/active_admin/wysihtml5/admin/assets.rb @@ -1,4 +1,4 @@ -ActiveAdmin.register Asset do +ActiveAdmin.register WysiHtmlFiveAsset do index as: :grid do |asset| link_to(image_tag(asset.storage.thumb("100x100#").url), admin_asset_path(asset)) @@ -42,7 +42,7 @@ def create # If an app is using Rack::RawUpload, it can just use # params['file'] and not worry with original_filename parsing. if params['file'] - @asset = Asset.new + @asset = WysiHtmlFiveAsset.new @asset.storage = params['file'] if @asset.save! @@ -51,7 +51,7 @@ def create render nothing: true, status: 500 and return end elsif params['qqfile'] - @asset = Asset.new + @asset = WysiHtmlFiveAsset.new io = request.env['rack.input'] # throw io @@ -73,4 +73,3 @@ def create end end - From fc04e1f58b55a3cd2c5a87aa926d2066bcb8a5b5 Mon Sep 17 00:00:00 2001 From: David Stump Date: Wed, 25 Mar 2015 11:14:12 -0400 Subject: [PATCH 2/2] Updates asset json path to point to the new namespaced wysi_html_five_assets.json --- app/assets/javascripts/activeadmin-wysihtml5/base.js.coffee | 5 ++--- .../wysihtml5/admin/{assets.rb => wysi_html_five_asset.rb} | 0 2 files changed, 2 insertions(+), 3 deletions(-) rename lib/active_admin/wysihtml5/admin/{assets.rb => wysi_html_five_asset.rb} (100%) diff --git a/app/assets/javascripts/activeadmin-wysihtml5/base.js.coffee b/app/assets/javascripts/activeadmin-wysihtml5/base.js.coffee index d94c729..4ea2743 100644 --- a/app/assets/javascripts/activeadmin-wysihtml5/base.js.coffee +++ b/app/assets/javascripts/activeadmin-wysihtml5/base.js.coffee @@ -103,7 +103,7 @@ refreshAssets = -> $gallery.empty() - $.getJSON '/admin/assets.json', (data) -> + $.getJSON '/admin/wysi_html_five_assets.json', (data) -> $.each data, (i, asset) -> $img = $("") $img.attr @@ -120,7 +120,7 @@ initUploader = -> uploader = new qq.FileUploader element: $uploader.get(0) - action: '/admin/assets.json' + action: '/admin/wysi_html_five_assets.json' onComplete: -> refreshAssets() $tab_handles.eq(1).click() @@ -205,4 +205,3 @@ ) )(jQuery) - diff --git a/lib/active_admin/wysihtml5/admin/assets.rb b/lib/active_admin/wysihtml5/admin/wysi_html_five_asset.rb similarity index 100% rename from lib/active_admin/wysihtml5/admin/assets.rb rename to lib/active_admin/wysihtml5/admin/wysi_html_five_asset.rb