Ubiquo template provides a simple media management for your application.
By default, the most common asset types are already created (video, flash, document, audio, image, other). Edit the fixtures file db/dev_bootstrap/asset_types.yml to add more.
Asset files will be store at public/media/assets/id.
The media library allows to insert a media field into a model. On this example we include a media_attachment attribute called images, with a maximum of 2 elements and accepting only images.
class ExampleModel
media_attachment :images, :size => 2, :types => ["image"]
...
end
Note: For convention, the attribute name should be always plural no matter if it contains a single element (size option is 1). The media_attachment accessor always returns an array.
media_attachment creates some methods on the object which can be useful on validations:
validates_length_of :images_ids, :minumum => 1, :message => t('should contain at least one image')
In your views you only need to use the media_selector helper:
<% form_for ... do |form| %>
....
<%= media_selector form, :images %>
....
<% end %>
Get an url to your media with url_for_media_attachment:
<%= link_to("a link to first image image", url_for_media_attachment(object.images.first)) %>
Generate url for your media columns with url_for_media_attachment and the magick version parameter:
<%= link_to("a link to first thumbnail image", url_for_media_attachment(object.thumbnail.first, :thumb)) %>
You can also specify paperclip styles to store different versions of the asset
Disabled; run with $DEBUG to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.