Commit 3a7a93d5 by Prem Sichanugrist

Update Readme to mention sexy migration

parent 77ee8a51
...@@ -94,15 +94,13 @@ In your model: ...@@ -94,15 +94,13 @@ In your model:
In your migrations: In your migrations:
class AddAvatarColumnsToUser < ActiveRecord::Migration class AddAvatarColumnsToUsers < ActiveRecord::Migration
def self.up def self.up
change_table :users do |t| add_attachment :users, :avatar
t.has_attached_file :avatar
end
end end
def self.down def self.down
drop_attached_file :users, :avatar remove_attachment :users, :avatar
end end
end end
...@@ -207,6 +205,57 @@ Paperclip::Attachment.default_options[:fog_directory] = "" ...@@ -207,6 +205,57 @@ Paperclip::Attachment.default_options[:fog_directory] = ""
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"} 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 Storage
------- -------
......
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