Skip to content

Instantly share code, notes, and snippets.

@gregblake
Created February 21, 2018 19:17
Show Gist options
  • Select an option

  • Save gregblake/6fb6988488bbddbd007712d2438b9660 to your computer and use it in GitHub Desktop.

Select an option

Save gregblake/6fb6988488bbddbd007712d2438b9660 to your computer and use it in GitHub Desktop.
Using Paperclip on the Rails Console
Loading development environment (Rails 5.1.4)
[1] pry(main)> document = Document.new
=> #<Document:0x007faaa2018e80
id: nil,
name: nil,
active: true,
created_by: nil,
roles_count: 0,
created_at: nil,
updated_at: nil,
territories_count: 0,
published_date_start: nil,
published_date_end: nil,
thumbnail_file_name: nil,
thumbnail_file_size: nil,
thumbnail_content_type: nil,
viewing_mode: "Download only">
[2] pry(main)> document.thumbnail = File.open("/Users/greg/Documents/icons/power-devs.png")
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/nn/mbmf5z1s37n3h11j5jtcc4s40000gn/T/6e448dd40eaf5782cf7aba64c6d63c7720180221-91590-q9zqzg.png[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/nn/mbmf5z1s37n3h11j5jtcc4s40000gn/T/6e448dd40eaf5782cf7aba64c6d63c7720180221-91590-q9zqzg.png[0]'
Command :: convert '/var/folders/nn/mbmf5z1s37n3h11j5jtcc4s40000gn/T/6e448dd40eaf5782cf7aba64c6d63c7720180221-91590-q9zqzg.png[0]' -auto-orient -resize "75x" -crop "75x75+0+0" +repage '/var/folders/nn/mbmf5z1s37n3h11j5jtcc4s40000gn/T/305871506e9afa9cf48a71d206ec866320180221-91590-10vvttu'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/nn/mbmf5z1s37n3h11j5jtcc4s40000gn/T/6e448dd40eaf5782cf7aba64c6d63c7720180221-91590-q9zqzg.png[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/nn/mbmf5z1s37n3h11j5jtcc4s40000gn/T/6e448dd40eaf5782cf7aba64c6d63c7720180221-91590-q9zqzg.png[0]'
Command :: convert '/var/folders/nn/mbmf5z1s37n3h11j5jtcc4s40000gn/T/6e448dd40eaf5782cf7aba64c6d63c7720180221-91590-q9zqzg.png[0]' -auto-orient -resize "256x" -crop "256x256+0+0" +repage '/var/folders/nn/mbmf5z1s37n3h11j5jtcc4s40000gn/T/305871506e9afa9cf48a71d206ec866320180221-91590-1mkfnkg'
=> #<File:/Users/greg/Documents/icons/power-devs.png>
[3] pry(main)> document.valid?
=> false
[4] pry(main)> document.errors.full_messages
=> ["Name can't be blank"]
[5] pry(main)> document.name = "Test"
=> "Test"
[6] pry(main)> document.save!
[write] (0.5ms) BEGIN
[write] SQL (2.9ms) INSERT INTO `documents` (`name`, `active`, `created_by`, `roles_count`, `created_at`, `updated_at`, `territories_count`, `published_date_start`, `published_date_end`, `thumbnail_file_name`, `thumbnail_file_size`, `thumbnail_content_type`, `viewing_mode`) VALUES ('Test', 1, NULL, 0, '2018-02-21 19:16:01', '2018-02-21 19:16:01', 0, NULL, NULL, 'power-devs.png', 6240, 'image/png', 'Download only')
[paperclip] saving documents/thumbnails/000/000/764/original/power-devs.png
[paperclip] saving documents/thumbnails/000/000/764/small/power-devs.png
[paperclip] saving documents/thumbnails/000/000/764/medium/power-devs.png
[write] (0.6ms) COMMIT
=> true
@gregblake
Copy link
Copy Markdown
Author

gregblake commented Feb 21, 2018

[8] pry(main)> document.thumbnail.short_expiring_url
[9] pry(main)> document
=> #<Document:0x007faaa2018e80
 id: 764,
 name: "Test",
 active: true,
 created_by: nil,
 roles_count: 0,
 created_at: Wed, 21 Feb 2018 14:16:01 EST -05:00,
 updated_at: Wed, 21 Feb 2018 14:16:01 EST -05:00,
 territories_count: 0,
 published_date_start: nil,
 published_date_end: nil,
 thumbnail_file_name: "power-devs.png",
 thumbnail_file_size: 6240,
 thumbnail_content_type: "image/png",
 viewing_mode: "Download only">
[10] pry(main)>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment