Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/attacheable.rb
Class Method Summary collapse
-
.has_attachment(options = {}) ⇒ Object
In model write has_attachment (conflicts with acts_as_attachment) with options:.
-
.validates_as_attachment(options = {}) ⇒ Object
Currently it will check valid filetype (unless option valid_filetypes set to :all).
Class Method Details
.has_attachment(options = {}) ⇒ Object
In model write has_attachment (conflicts with acts_as_attachment) with options:
:thumbnails => list of thumbnails, i.e. => “120x”, :large => “800x600” :croppable_thumbnails => list of thumbnails, which must be cropped to center, i.e.: [:large, :preview] :path_prefix => path, where to store photos, i.e.: “public/system/photos” :replicas => [=> “user1”, :host => “host1”], list of hosts, where to clone all loaded originals :autocreate => true/false, whether to autocreate thumbnails on requesting thumbnail
After this, add to routes:
map.assets 'system/photos/*path_info', :controller => "photos", :action => "show"
and add to PhotosController: def show
photo, data = Photo.data_by_path_info(params[:path_info])
render :text => data, :content_type => photo && photo.content_type
end This will enable creation on demand
You can also add
uri "/system/photos/", :handler => Attacheable::PhotoHandler.new("/system/photos"), :in_front => true
to any mongrel scripts for nonblocking image creation
Table for this plugin should have fields:
filename : string
content_type : string (optional)
width : integer (optional)
heigth : integer (optional)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/attacheable.rb', line 33 def self.( = {}) class_inheritable_accessor :attachment_options self. = .with_indifferent_access [:autocreate] ||= false [:force_autocreate] ||= false [:thumbnails] ||= {} [:thumbnails].symbolize_keys!.with_indifferent_access [:croppable_thumbnails] ||= [] [:croppable_thumbnails] = [:croppable_thumbnails].map(&:to_sym) [:path_prefix] ||= "public/system/#{table_name}" [:valid_filetypes] ||= %w(jpeg gif png psd) include(Attacheable) end |
.validates_as_attachment(options = {}) ⇒ Object
Currently it will check valid filetype (unless option valid_filetypes set to :all)
52 53 54 55 56 57 |
# File 'lib/attacheable.rb', line 52 def self.( = {}) [:message] ||= "Incorrect file type. Valid file types include: #{[:valid_filetypes].to_sentence}" self.[:validation_message] = [:message] validate :valid_filetype? end |