Created
March 16, 2012 16:15
-
-
Save EricLondon/2050793 to your computer and use it in GitHub Desktop.
Programmatically create paperclip attachment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.9.2-p290 :002 > u = Upload.new | |
=> #<Upload id: nil, post_id: nil, created_at: nil, updated_at: nil, upload_file_name: nil, upload_content_type: nil, upload_file_size: nil, upload_updated_at: nil> | |
1.9.2-p290 :004 > u.upload = File.open('/Users/Eric/Desktop/estimation grid.png') | |
=> #<File:/Users/Eric/Desktop/estimation grid.png> | |
1.9.2-p290 :005 > u.save! | |
(0.1ms) begin transaction | |
SQL (17.4ms) INSERT INTO "uploads" ("created_at", "post_id", "updated_at", "upload_content_type", "upload_file_name", "upload_file_size", "upload_updated_at") VALUES (?, ?, ?, ?, ?, ?, ?) [["created_at", Fri, 16 Mar 2012 16:13:46 UTC +00:00], ["post_id", nil], ["updated_at", Fri, 16 Mar 2012 16:13:46 UTC +00:00], ["upload_content_type", "image/png"], ["upload_file_name", "estimation_grid.png"], ["upload_file_size", 53079], ["upload_updated_at", Fri, 16 Mar 2012 16:13:43 UTC +00:00]] | |
(23.8ms) commit transaction | |
=> true | |
########## | |
1.9.2-p290 :007 > Upload.create!(:upload => File.open('/Users/Eric/Desktop/estimation grid.png')) | |
(0.1ms) begin transaction | |
SQL (69.0ms) INSERT INTO "uploads" ("created_at", "post_id", "updated_at", "upload_content_type", "upload_file_name", "upload_file_size", "upload_updated_at") VALUES (?, ?, ?, ?, ?, ?, ?) [["created_at", Fri, 16 Mar 2012 16:19:53 UTC +00:00], ["post_id", nil], ["updated_at", Fri, 16 Mar 2012 16:19:53 UTC +00:00], ["upload_content_type", "image/png"], ["upload_file_name", "estimation_grid.png"], ["upload_file_size", 53079], ["upload_updated_at", Fri, 16 Mar 2012 16:19:53 UTC +00:00]] | |
(13.8ms) commit transaction | |
=> #<Upload id: 4, post_id: nil, created_at: "2012-03-16 16:19:53", updated_at: "2012-03-16 16:19:53", upload_file_name: "estimation_grid.png", upload_content_type: "image/png", upload_file_size: 53079, upload_updated_at: "2012-03-16 16:19:53"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment