Commit 403e6283 by jyurek

README update and default style

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@161 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 13318e61
Paperclip
=========
Paperclip is a lightweight attachment manager for ActiveRecord. It saves and manages your attachments be they images or Word Doc with one line of code. You can automatically thumbnail images as they're uploaded, and you don't have to worry about installing any ruby-specific libraries. You don't have to worry about compiling headaches with RMagick, concurrency issues and race conditions with MiniMagick, or unsupported image types with ImageScience. All you need is a working Image- or GraphicsMagick installation.
Paperclip is a lightweight attachment manager for ActiveRecord. It saves and manages your attachments, be they images or Word Docs, with one line of code. You can automatically thumbnail images as they're uploaded, and you don't have to worry about installing any ruby-specific libraries. You don't have to worry about compiling headaches with RMagick, concurrency issues and race conditions with MiniMagick, or unsupported image types with ImageScience. All you need is a working Image- or GraphicsMagick installation -- the convert command is all you need.
Paperclip uses the filesystem to save your files. You specify a root that the files will be saved to, and, if you're attaching images, any other formats they need to be converted to, and they'll all be saved to the right place when your object saves. They can even validate beforehand, so you'll know if your user tries to upload an HTML doc as an image.
......@@ -14,7 +14,7 @@ class Photo < ActiveRecord::Base
has_attached_file :image, :thumbnails => { :medium => "300x300>", :thumb => "100x100>" }
end
In your view:
In your edit and new views:
<% form_for :photo, @photo, :url => photo_path do |form| %>
<%= form.file_field :image %>
......@@ -25,3 +25,9 @@ In your controller:
def create
@photo = Photo.create( params[:photo] )
end
In your show view:
<%= image_path @photo.image_url(:original) %>
<%= image_path @photo.image_url(:medium) %>
<%= image_path @photo.image_url(:thumb) %>
\ No newline at end of file
......@@ -84,7 +84,7 @@ module Thoughtbot
module InstanceMethods
def path_for attachment, style
def path_for attachment, style = :original
prefix = File.join(attachment[:path_prefix], attachment[:path])
prefix.gsub!(/:rails_root/, RAILS_ROOT)
prefix.gsub!(/:id/, self.id.to_s) if self.id
......@@ -93,7 +93,7 @@ module Thoughtbot
File.join( prefix.split("/"), read_attribute("#{attachment[:name]}_file_name") )
end
def url_for attachment, style
def url_for attachment, style = :original
prefix = File.join(attachment[:url_prefix], attachment[:path])
prefix.gsub!(/:rails_root/, RAILS_ROOT)
prefix.gsub!(/:id/, self.id.to_s) if self.id
......
......@@ -304,3 +304,55 @@

SQL (0.000451) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
SQL (0.000495) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
SQL (0.000648) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
Foo Destroy (0.000453)  DELETE FROM foos
WHERE id = 3

SQL (0.000567) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
SQL (0.000520) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
SQL (0.000581) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
Bar Destroy (0.000439)  DELETE FROM bars
WHERE id = 3

SQL (0.000420) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
SQL (0.000442) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
SQL (0.000611) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
Foo Destroy (0.000472)  DELETE FROM foos
WHERE id = 5

SQL (0.000478) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
SQL (0.000600) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
SQL (0.000529) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
Bar Destroy (0.000442)  DELETE FROM bars
WHERE id = 5

SQL (0.000619) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
SQL (0.000440) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
SQL (0.000613) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
Foo Destroy (0.000430)  DELETE FROM foos
WHERE id = 7

SQL (0.000461) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
SQL (0.000472) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
SQL (0.000498) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
Bar Destroy (0.000436)  DELETE FROM bars
WHERE id = 7

SQL (0.000452) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
SQL (0.000447) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
SQL (0.000719) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
Foo Destroy (0.000398)  DELETE FROM foos
WHERE id = 9

SQL (0.000482) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
SQL (0.000611) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
SQL (0.000506) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
Bar Destroy (0.000414)  DELETE FROM bars
WHERE id = 9

SQL (0.000548) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
SQL (0.000462) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
......@@ -23,9 +23,9 @@ class PaperclipImagesTest < Test::Unit::TestCase
assert File.size?( @foo.image_filename(:original) )
assert File.size?( @foo.image_filename(:medium) )
assert File.size?( @foo.image_filename(:thumb) )
`identify '#{@foo.image_filename(:original)}'`; assert $?.exitstatus == 0
`identify '#{@foo.image_filename(:medium)}'`; assert $?.exitstatus == 0
`identify '#{@foo.image_filename(:thumb)}'`; assert $?.exitstatus == 0
out = `identify '#{@foo.image_filename(:original)}'`; assert out.match("405x375"); assert $?.exitstatus == 0
out = `identify '#{@foo.image_filename(:medium)}'`; assert out.match("300x278"); assert $?.exitstatus == 0
out = `identify '#{@foo.image_filename(:thumb)}'`; assert out.match("100x93"); assert $?.exitstatus == 0
end
def test_should_validate_to_make_sure_the_thumbnails_exist
......
......@@ -26,6 +26,11 @@ class PaperclipTest < Test::Unit::TestCase
assert @bar.valid?
end
def test_should_default_to_original_for_path_and_url
assert_equal @bar.document_filename(:original), @bar.document_filename
assert_equal @bar.document_url(:original), @bar.document_url
end
def test_should_delete_files_on_destroy
assert @bar.save
assert File.exists?( @bar.document_filename )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment