diff --git a/.gitignore b/.gitignore
index db27736..4378c3e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,4 @@ spec/dummy/public/system/
Gemfile.lock
tmp/
.rbenv-gemsets
+.env
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
index 06fe80f..8622f5f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,6 +3,7 @@ source "https://rubygems.org"
# Declare your gem's dependencies in smithycms.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
+
gemspec
# Declare any dependencies that are still in development here instead of in
diff --git a/app/controllers/smithy/assets_controller.rb b/app/controllers/smithy/assets_controller.rb
index 3a9baef..0618ef6 100644
--- a/app/controllers/smithy/assets_controller.rb
+++ b/app/controllers/smithy/assets_controller.rb
@@ -16,6 +16,7 @@ def new
def create
@asset = Asset.new(filtered_params)
+ @asset.set_name(filtered_params)
@asset.save
flash.notice = "Your asset was created" if @asset.persisted?
respond_with @asset do |format|
diff --git a/app/models/smithy/asset.rb b/app/models/smithy/asset.rb
index 7824488..59f616a 100644
--- a/app/models/smithy/asset.rb
+++ b/app/models/smithy/asset.rb
@@ -1,31 +1,30 @@
module Smithy
class Asset < ActiveRecord::Base
validates_presence_of :file, :name
+ attachment :file
has_many :images, :dependent => :destroy
- extend ::Dragonfly::Model
- dragonfly_accessor :file
- include ::Smithy::Dragonfly::AssetHelper
-
- before_validation :set_name
- before_save :set_file_uid_manually
+ # extend ::Dragonfly::Model
+ # dragonfly_accessor :file
+ # include ::Smithy::Dragonfly::AssetHelper
+ # before_save :set_file_uid_manually
default_scope -> { order(:name) }
- def file
- # check for the jquery uploaded file first, just in case one got past the manual check. Also keeps backwards-compatibility
- if self.uploaded_file_url?
- dragonfly_attachments[:file].app.datastore = self.class.dragonfly_remote_datastore
- self.file_url = URI.escape(self.uploaded_file_url)
- elsif dragonfly_attachments[:file].to_value
- dragonfly_attachments[:file].app.datastore = self.class.dragonfly_datastore
- end
- dragonfly_attachments[:file].to_value
- end
+ # def file
+ # # check for the jquery uploaded file first, just in case one got past the manual check. Also keeps backwards-compatibility
+ # # if self.uploaded_file_url?
+ # # dragonfly_attachments[:file].app.datastore = self.class.dragonfly_remote_datastore
+ # # self.file_url = URI.escape(self.uploaded_file_url)
+ # # elsif dragonfly_attachments[:file].to_value
+ # # dragonfly_attachments[:file].app.datastore = self.class.dragonfly_datastore
+ # # end
+ # # dragonfly_attachments[:file].to_value
+ # end
def file_type
- ext = File.extname(file.name).sub(/^\./, '')
+ ext = File.extname(self.name).sub(/^\./, '')
case ext
when 'jpg', 'jpeg', 'gif', 'png'
:image
@@ -63,27 +62,26 @@ def to_liquid
}
end
- private
- def set_content_types
- set_content_type(self.file, :content_type)
+ def set_name(params)
+ filename = params[:file].original_filename
+ if filename && !self.name?
+ self.name = filename
end
+ end
- # this allows dragonfly to take over management of the uploaded file. We are
- # assuming that jquery-upload and dragonfly are using the same data storage...
- def set_file_uid_manually
- if self.uploaded_file_url? # this means it was uploaded via jquery-upload
- uri = URI.parse(URI.encode(self.uploaded_file_url))
- self.file_uid = self.uploaded_file_url.sub("#{uri.scheme}://#{uri.host}/", '')
- self.uploaded_file_url = nil
- end
- end
+ private
+ # def set_content_types
+ # set_content_type(self.file, :content_type)
+ # end
- def set_name
- if self.uploaded_file_url?
- self.name = File.basename(self.uploaded_file_url, '.*').titleize unless self.name?
- elsif self.file.present?
- self.name = File.basename(self.file.name, '.*').titleize unless self.name?
- end
- end
+ # # this allows dragonfly to take over management of the uploaded file. We are
+ # # assuming that jquery-upload and dragonfly are using the same data storage...
+ # def set_file_uid_manually
+ # if self.uploaded_file_url? # this means it was uploaded via jquery-upload
+ # uri = URI.parse(URI.encode(self.uploaded_file_url))
+ # self.file_uid = self.uploaded_file_url.sub("#{uri.scheme}://#{uri.host}/", '')
+ # self.uploaded_file_url = nil
+ # end
+ # end
end
end
diff --git a/app/views/smithy/assets/_asset.html.erb b/app/views/smithy/assets/_asset.html.erb
index 27fadb8..377ab1a 100644
--- a/app/views/smithy/assets/_asset.html.erb
+++ b/app/views/smithy/assets/_asset.html.erb
@@ -1,8 +1,8 @@