Skip to content

Commit

Permalink
Update Readme to mention sexy migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sikachu committed Jun 15, 2012
1 parent 77ee8a5 commit 3a7a93d
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,13 @@ In your model:

In your migrations:

class AddAvatarColumnsToUser < ActiveRecord::Migration
class AddAvatarColumnsToUsers < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.has_attached_file :avatar
end
add_attachment :users, :avatar
end

def self.down
drop_attached_file :users, :avatar
remove_attachment :users, :avatar
end
end

Expand Down Expand Up @@ -184,7 +182,7 @@ Defaults
--------
Global defaults for all your paperclip attachments can be defined by changing the Paperclip::Attachment.default_options Hash, this can be useful for setting your default storage settings per example so you won't have to define them in every has_attached_file definition.

If you're using Rails you can define a Hash with default options in config/application.rb or in any of the config/environments/*.rb files on config.paperclip_defaults, these well get merged into Paperclip::Attachment.default_options as your Rails app boots. An example:
If you're using Rails you can define a Hash with default options in config/application.rb or in any of the config/environments/*.rb files on config.paperclip_defaults, these well get merged into Paperclip::Attachment.default_options as your Rails app boots. An example:

```ruby
module YourApp
Expand All @@ -207,6 +205,57 @@ Paperclip::Attachment.default_options[:fog_directory] = ""
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"}
```

Migrations
----------

Paperclip defines several migration methods which can be used to create necessary columns in your
model. There are two types of method:

### Table Definition

class AddAttachmentToUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.attachment :avatar
end
end
end

If you're using Rails 3.2 or newer, this method works in `change` method as well:

class AddAttachmentToUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.attachment :avatar
end
end
end

### Schema Definition

class AddAttachmentToUsers < ActiveRecord::Migration
def self.up
add_attachment :users, :avatar
end

def self.down
remove_attachment :users, :avatar
end
end

If you're using Rails 3.2 or newer, you only need `add_attachment` in your `change` method:

class AddAttachmentToUsers < ActiveRecord::Migration
def change
add_attachment :users, :avatar
end
end

### Vintage syntax

Vintage syntax (such as `t.has_attached_file` and `drop_attaached_file`) are still supported in
Paperclip 3.x, but you're advised to update those migration files to use this new syntax.

Storage
-------

Expand Down

0 comments on commit 3a7a93d

Please sign in to comment.