Module: AttachmentMagic::ActMethods
- Defined in:
- lib/attachment_magic.rb
Instance Method Summary collapse
-
#has_attachment(options = {}) ⇒ Object
Options: *
:content_type
- Allowed content types.
Instance Method Details
#has_attachment(options = {}) ⇒ Object
Options:
-
:content_type
- Allowed content types. Allows all by default. Use :image to allow all standard image types. -
:min_size
- Minimum size allowed. 1 byte is the default. -
:max_size
- Maximum size allowed. 1.megabyte is the default. -
:size
- Range of sizes allowed. (1..1.megabyte) is the default. This overrides the :min_size and :max_size options. -
:path_prefix
- path to store the uploaded files. Uses public/#table_name by default. -
:storage
- Use :file_system to specify the attachment data is stored with the file system. Defaults to :file_system.
Examples:
:max_size => 1.kilobyte
:size => 1.megabyte..2.megabytes
:content_type => 'application/pdf'
:content_type => ['application/pdf', 'application/msword', 'text/plain']
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/attachment_magic.rb', line 62 def ( = {}) # this allows you to redefine the acts' options for each subclass, however [:min_size] ||= 1 [:max_size] ||= 1.megabyte [:size] ||= ([:min_size]..[:max_size]) [:content_type] = [[:content_type]].flatten.collect! { |t| t == :image ? AttachmentMagic.content_types : t }.flatten unless [:content_type].nil? extend ClassMethods unless (class << self; included_modules; end).include?(ClassMethods) include InstanceMethods unless included_modules.include?(InstanceMethods) = || {} # doing these shenanigans so that #attachment_options is available to processors and backends self. = [:storage] ||= :file_system [:storage] ||= [:storage] [:path_prefix] ||= [:file_system_path] if [:path_prefix].nil? File.join("public", table_name) end [:path_prefix] = [:path_prefix][1..-1] if [:path_prefix].first == '/' unless File.directory?(AttachmentMagic.tempfile_path) FileUtils.mkdir_p(AttachmentMagic.tempfile_path) end storage_mod = AttachmentMagic::Backends.const_get("#{[:storage].to_s.classify}Backend") include storage_mod unless included_modules.include?(storage_mod) end |