Method: Cms::Behaviors::Attaching::ClassMethods#has_attachment

Defined in:
lib/cms/behaviors/attaching.rb

#has_attachment(name, options = {}) ⇒ Object

Defines an single attachement with a given name.

Parameters:

  • name (Symbol)

    The name of the attachment

  • options (Hash) (defaults to: {})

    Accepts most Paperclip options for Paperclip::ClassMethods.has_attached_file

See Also:



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/cms/behaviors/attaching.rb', line 161

def has_attachment(name, options = {})
  options[:type] = :single
  options[:index] = Cms::Attachment.definitions[self.name].size
  Cms::Attachment.definitions[self.name][name] = options

  define_method name do
    attachment_named(name)
  end
  define_method "#{name}?" do
    (attachment_named(name) != nil)
  end
end