README.rdoc in rails_uploads-0.1.5 vs README.rdoc in rails_uploads-0.2.0
- old
+ new
@@ -1,6 +1,7 @@
-=== NOTE: From version 0.1.5 and above defaults must be put in public/uploads folder
+=== NOTE: From version 0.1.5 and above defaults must be in public folder
+=== NOTE: From version 0.2.0 and above the use of path is deprecated
---
{<img src="https://codeclimate.com/github/mattways/rails_uploads.png" />}[https://codeclimate.com/github/mattways/rails_uploads] {<img src="https://travis-ci.org/mattways/rails_uploads.png?branch=master" alt="Build Status" />}[https://travis-ci.org/mattways/rails_uploads] {<img src="https://gemnasium.com/mattways/rails_uploads.png" alt="Dependency Status" />}[https://gemnasium.com/mattways/rails_uploads]
@@ -13,10 +14,13 @@
Put this line in your Gemfile:
gem 'rails_uploads'
Then bundle:
$ bundle
+
+ImageMagick must be install, you can install it with homebrew:
+ brew install imagemagick
= Usage
Mount the engine at the end of you routes.rb:
mount RailsUploads::Engine => '/' # Will be use to generate on the fly missing image presets
@@ -43,11 +47,28 @@
:big => { :method => :fit, :width => 1024, :height => 768 }, # Fit will scale the image until it fit in the space without cropping
:small => { :method => :fill, :width => 120, :height => :120 }, # Fill will scale the image to fill all the space and then crop
:custom => proc { |image| image.convert :resize => '100x100' } # ImageMagick wrapper to do whatever you want
}
config.uploads.default_presets = [:small] # Define the default presets for all models with attached images
+ config.uploads.storage = :local # The default it's local, you can use :s3 as well
+If you want to use S3 create a s3.yml file in your config directory like this:
+ development:
+ bucket: development-bucket
+ access_key_id: development_access_key_id
+ secret_access_key: development_secret_access_key
+
+ test:
+ bucket: test-bucket
+ access_key_id: test_access_key_id
+ secret_access_key: test_secret_access_key
+
+ production:
+ bucket: production-bucket
+ access_key_id: production_access_key_id
+ secret_access_key: production_secret_access_key
+
The validation works very similar to paperclip:
class Model < ActiveRecord::Base
attr_accessible :prop
attached_file :prop
validates :prop, :attachment_presence => true, :attachment_size => { :in => 0..4.megabytes }, :attachment_content_type => { :in => ['txt'] }
@@ -59,29 +80,34 @@
errors.messages.attachment_size_less_than # :less_than
errors.messages.attachment_size_greater_than # :greater_than
errors.messages.attachment_content_type # :types
In your views:
- a{ :href => record.file.path } # To get the file
- a{ :href => record.image.path } # To get the original image
- a{ :href => record.image.path(:big) } # To get the thumb
- a{ :href => record.image.url(:big) } # If you want to use a base url
+ a{ :href => record.file.url } # To get the file url
+ a{ :href => record.image.url } # To get the original image
+ a{ :href => record.image.url(:big) } # To get the a thumb
In your forms:
= f.file_field :prop
= FAQ
== How can I use a cdn with this plugin?
-Just define a base url in your application.rb and use url method instead of path:
- config.uploads.base_url = 'http://example.com'
+Just define a base url in your application.rb:
+ config.uploads.base_url = 'http://cdn.example.com'
+
+== Can I automatically create buckets?
+
+Yes, use this rake task after create the s3.yml file:
+ rake uploads:s3:buckets:create
== How can I clean a preset?
-Just remove the corresponding folder in uploads/images manually or with rake task:
- rake uploads:preset:clean[preset]
+Just remove the corresponding folder in uploads/images manually or with this rake task:
+ rake uploads:preset:clean NAME=preset
== How to migrate from versions before 0.1.0?
To migrate from versions before 0.1.0 you need to reorganize uploads with this task after define your presets in your application.rb:
rake uploads:migrate
+