Skip to content
Media Managment Library for ActiveRecord and Carrierwave
Ruby JavaScript
Find file
Pull request Compare This branch is even with AF83:rails2.3.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
examples
generators/has_media
lib
spec
.document
.gitignore
.rspec
LICENSE
README.rdoc
Rakefile
VERSION
has_media.gemspec

README.rdoc

Has Media

Media Managment Library for ActiveRecord and Carrierwave

Easy way to link media (ie image, audio, video, pdf, …) on other activerecords models

Use branch rails2.3 for Rails 2.3.x and rails3 for Rails 3

Create migrations

./script/generate has_media

Usage

has_one_medium  :image, :only => :image
has_many_media  :images, :only => :image

has_one_medium  :audio, :only => :audio
has_many_media  :audios, :only => :audio

has_one_medium  :image_no_encode, :only => :image, :encode => false

has_one_medium  :pdf, :encode => false

Model and Uploaders

You must defined model and uploader with the name given in the only option Examples are in the /examples directory…

Configuration

* Configuration take place in config/initializers/has_media.rb

* Set the directory path to use to store media
 HasMedia.directory_path = "media"

* Set the base uri to access media
 HasMedia.directory_uri = "/media"

* Set custom error messages
 HasMedia.errors_messages = {:type_error => I18n.t('has_media.errors.type_error')}

* Set the allowed medium types for your application (used if no :only option given)
 HasMedia.medium_types = [Image, Video, Audio]

* Set the extension of encoded files to use for each medium types (used in file_uri and file_path)
 HasMedia.encoded_extensions = {
   :image => 'png',
   :audio => 'ogg',
   :video => 'flv'
 }

* Require you uploaders 
 Dir.glob(File.dirname(__FILE__) + '/../app/uploaders/*.rb').each do |uploader|
   require uploader
 end

Testing

Factory example using factory_girl :

Factory.define :image, :class => Image do |f| 
  f.content_type 'image/jpeg'
  f.filename 'image.jpg'
  f.status 'accepted'
  f.encode_status 0
  f.add_attribute :context, 'images'
  f.file {ActionController::TestUploadedFile.new(File.join(Rails.root, '/spec/factories/image.jpg'), 'image/jpeg')}
end

TODO

* Doc for testing (ActionController::TestUploadedFile is now obsolete in rails 3), add HasMediaTestHelper with stub_temp_file method
* Generator for initializer
* Add controller and views examples with overload system (form fields, display, ...)
* Fix problem with migrations generator timestamps
* Generator for models and uploaders (Type in Image, Video, Audio, Pdf) :
 rails generate has_media_model Type Name

Contributors

klacointe, spk, shingara, nono

Copyright

Copyright © 2009 AF83. See LICENSE for details.

Something went wrong with that request. Please try again.