Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9230089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:44:16+00:00 2026-06-18T05:44:16+00:00

EDIT: One problem was I need to do r = Resource.where(id: 3).first #<== I

  • 0

EDIT: One problem was I need to do r = Resource.where(id: 3).first #<== I didn’t have the .first before

I’m attempting to get snapshots of URLs by using imgkit + paperclip + s3. I am able to get the snapshots, and successfully upload them to paperclip. For example, the IRB session at the bottom of this post successfully uploads a snapshot of the specified URL to my S3 bucket.

However, I am trying to display the images, and I always get a missing.png image. I experimented in the IRB session given below and found something interesting. I don’t think that I am saving resource.snapshot correctly, because I can’t get that url again if I find the resource under a different variable name (look at the IRB session below).

All I want to know is how I can get the url of the image I uploaded to S3.

I ran “rails generate paperclip resource snapshot” and then “rake db:migrate” successfully.

Gemfile:

# IMGKit for site thumbnails
gem "imgkit", "~> 1.3.7"

# Amazon S3 storage
gem 'aws-sdk', '~> 1.3.4'

# Paperclip for file uploads
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"

In my resource.rb model:

attr_accessible :snapshot
  has_attached_file :snapshot,
                    :storage => :s3,
                    :s3_credentials => "#{Rails.root}/config/s3.yml"

Here’s my IRB session:

128-110-88-73:KnowledgeThief dainewinters$ rails c
    Loading development environment (Rails 3.2.11)
    irb(main):001:0> r = Resource.first
      Resource Load (0.9ms)  SELECT "resources".* FROM "resources" LIMIT 1
    => nil
    irb(main):002:0> r = Resource.first
      Resource Load (1.1ms)  SELECT "resources".* FROM "resources" LIMIT 1
    => #<Resource id: 1, link: "http://cm.dce.harvard.edu/2012/01/13836/publication...", title: "Harvard CS61 - Computer Systems", description: "Harvard's version of CS4400. Topics include assembl...", user_id: nil, created_at: "2013-02-03 20:36:01", updated_at: "2013-02-03 20:36:01", youtubeID: nil, media_type: "video", snapshot_file_name: nil, snapshot_content_type: nil, snapshot_file_size: nil, snapshot_updated_at: nil>
    irb(main):003:0> url = r.link
    => "http://cm.dce.harvard.edu/2012/01/13836/publicationListing.shtml"
    irb(main):004:0> url = PostRank::URI.clean(r.link)
    => "http://cm.dce.harvard.edu/2012/01/13836/publicationListing.shtml"
    irb(main):005:0> side_size = 300
    => 300
    irb(main):006:0> crop_side_size = 300
    => 300
    irb(main):007:0> kit = IMGKit.new(url, :quality => 50,
    irb(main):008:1*                           :width   => side_size,
    irb(main):009:1*                           :height  => side_size,
    irb(main):010:1*                           "crop-w" => crop_side_size,
    irb(main):011:1*                           "crop-h" => crop_side_size,
    irb(main):012:1*                           "zoom"   => 0.35,
    irb(main):013:1*                           "disable-smart-width" => true,
    irb(main):014:1*                           "load-error-handling" => "ignore")
    => #<IMGKit:0x007fa11599adc8 @options={:quality=>50, :width=>300, :height=>300, "crop-w"=>300, "crop-h"=>300, "zoom"=>0.35, "disable-smart-width"=>true, "load-error-handling"=>"ignore"}, @stylesheets=[], @source=http://cm.dce.harvard.edu/2012/01/13836/publicationListing.shtml>
    irb(main):015:0> img = kit.to_img(:jpg)
    => "\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x01..."
    irb(main):016:0> r.id
    => 1
    irb(main):017:0> r.object_id
    => 70164904582860
    irb(main):018:0> file = Tempfile.new(["resource_snapshot_#{r.id}
    irb(main):019:2" ", 'jpg'], 'tmp', :encoding => 'ascii-8bit')
    => #<File:/Users/dainewinters/rails/KnowledgeThief/tmp/resource_snapshot_1
    20130203-28526-1fpqdwljpg>
    irb(main):020:0> file.write(img)
    => 9756
    irb(main):021:0> file.flush
    => #<File:/Users/dainewinters/rails/KnowledgeThief/tmp/resource_snapshot_1
    20130203-28526-1fpqdwljpg>
    irb(main):022:0> r.snapshot
    => /snapshots/original/missing.png
    irb(main):023:0> r.snapshot = file
    => #<File:/Users/dainewinters/rails/KnowledgeThief/tmp/resource_snapshot_1
    20130203-28526-1fpqdwljpg>
    irb(main):024:0> r.snapshot
    => http://s3.amazonaws.com/knowledgethief-dev/resources/snapshots/000/000/001/original/resource_snapshot_1%0A20130203-28526-1fpqdwljpg?1359924148
    irb(main):025:0> r.save!
       (0.2ms)  BEGIN
       (0.9ms)  UPDATE "resources" SET "snapshot_file_name" = 'resource_snapshot_1
    20130203-28526-1fpqdwljpg', "snapshot_content_type" = 'image/jpeg', "snapshot_file_size" = 9756, "snapshot_updated_at" = '2013-02-03 20:42:28.408205', "updated_at" = '2013-02-03 20:42:35.031108' WHERE "resources"."id" = 1
       (0.8ms)  COMMIT
    => true
    irb(main):026:0> r
    => #<Resource id: 1, link: "http://cm.dce.harvard.edu/2012/01/13836/publication...", title: "Harvard CS61 - Computer Systems", description: "Harvard's version of CS4400. Topics include assembl...", user_id: nil, created_at: "2013-02-03 20:36:01", updated_at: "2013-02-03 20:42:35", youtubeID: nil, media_type: "video", snapshot_file_name: "resource_snapshot_1\n20130203-28526-1fpqdwljpg", snapshot_content_type: "image/jpeg", snapshot_file_size: 9756, snapshot_updated_at: "2013-02-03 20:42:28">
    irb(main):027:0> r.snapshot
    => http://s3.amazonaws.com/knowledgethief-dev/resources/snapshots/000/000/001/original/resource_snapshot_1%0A20130203-28526-1fpqdwljpg?1359924148
    irb(main):028:0> file.unlink
    => nil
    irb(main):029:0> r.snapshot
    => http://s3.amazonaws.com/knowledgethief-dev/resources/snapshots/000/000/001/original/resource_snapshot_1%0A20130203-28526-1fpqdwljpg?1359924148
    irb(main):030:0> r.snapshot.url
    => "http://s3.amazonaws.com/knowledgethief-dev/resources/snapshots/000/000/001/original/resource_snapshot_1%0A20130203-28526-1fpqdwljpg?1359924148"
    irb(main):031:0> r2 = Resource.first
      Resource Load (2.3ms)  SELECT "resources".* FROM "resources" LIMIT 1
    => #<Resource id: 2, link: "http://www.codeschool.com/courses/try-git", title: "Try Git", description: "A great introduction to Git, a popular version cont...", user_id: nil, created_at: "2013-02-03 20:36:01", updated_at: "2013-02-03 20:36:01", youtubeID: nil, media_type: "interactive course", snapshot_file_name: nil, snapshot_content_type: nil, snapshot_file_size: nil, snapshot_updated_at: nil>
    irb(main):032:0> r2
    => #<Resource id: 2, link: "http://www.codeschool.com/courses/try-git", title: "Try Git", description: "A great introduction to Git, a popular version cont...", user_id: nil, created_at: "2013-02-03 20:36:01", updated_at: "2013-02-03 20:36:01", youtubeID: nil, media_type: "interactive course", snapshot_file_name: nil, snapshot_content_type: nil, snapshot_file_size: nil, snapshot_updated_at: nil>
    irb(main):033:0> r2.snapshot
    => /snapshots/original/missing.png
    irb(main):034:0> r
    => #<Resource id: 1, link: "http://cm.dce.harvard.edu/2012/01/13836/publication...", title: "Harvard CS61 - Computer Systems", description: "Harvard's version of CS4400. Topics include assembl...", user_id: nil, created_at: "2013-02-03 20:36:01", updated_at: "2013-02-03 20:42:35", youtubeID: nil, media_type: "video", snapshot_file_name: "resource_snapshot_1\n20130203-28526-1fpqdwljpg", snapshot_content_type: "image/jpeg", snapshot_file_size: 9756, snapshot_updated_at: "2013-02-03 20:42:28">
    irb(main):035:0> r2 = Resource.where(id: 1)
      Resource Load (0.6ms)  SELECT "resources".* FROM "resources" WHERE "resources"."id" = 1
    => [#<Resource id: 1, link: "http://cm.dce.harvard.edu/2012/01/13836/publication...", title: "Harvard CS61 - Computer Systems", description: "Harvard's version of CS4400. Topics include assembl...", user_id: nil, created_at: "2013-02-03 20:36:01", updated_at: "2013-02-03 20:42:35", youtubeID: nil, media_type: "video", snapshot_file_name: "resource_snapshot_1\n20130203-28526-1fpqdwljpg", snapshot_content_type: "image/jpeg", snapshot_file_size: 9756, snapshot_updated_at: "2013-02-03 20:42:28">]
    irb(main):036:0> r2
    => [#<Resource id: 1, link: "http://cm.dce.harvard.edu/2012/01/13836/publication...", title: "Harvard CS61 - Computer Systems", description: "Harvard's version of CS4400. Topics include assembl...", user_id: nil, created_at: "2013-02-03 20:36:01", updated_at: "2013-02-03 20:42:35", youtubeID: nil, media_type: "video", snapshot_file_name: "resource_snapshot_1\n20130203-28526-1fpqdwljpg", snapshot_content_type: "image/jpeg", snapshot_file_size: 9756, snapshot_updated_at: "2013-02-03 20:42:28">]
    irb(main):037:0> r2.snapshot
    NoMethodError: undefined method `snapshot' for #<ActiveRecord::Relation:0x007fa115d42b88>
        from /Users/dainewinters/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/relation/delegation.rb:45:in `method_missing'
        from (irb):37
        from /Users/dainewinters/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
        from /Users/dainewinters/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
        from /Users/dainewinters/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
        from script/rails:12:in `require'
        from script/rails:12:in `<main>'
    irb(main):038:0> r2.snapshot_file_name
    NoMethodError: undefined method `snapshot_file_name' for #<ActiveRecord::Relation:0x007fa115d42b88>
        from /Users/dainewinters/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/relation/delegation.rb:45:in `method_missing'
        from (irb):38
        from /Users/dainewinters/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
        from /Users/dainewinters/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
        from /Users/dainewinters/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
        from script/rails:12:in `require'
        from script/rails:12:in `<main>'
    irb(main):039:0> r2
    => [#<Resource id: 1, link: "http://cm.dce.harvard.edu/2012/01/13836/publication...", title: "Harvard CS61 - Computer Systems", description: "Harvard's version of CS4400. Topics include assembl...", user_id: nil, created_at: "2013-02-03 20:36:01", updated_at: "2013-02-03 20:42:35", youtubeID: nil, media_type: "video", snapshot_file_name: "resource_snapshot_1\n20130203-28526-1fpqdwljpg", snapshot_content_type: "image/jpeg", snapshot_file_size: 9756, snapshot_updated_at: "2013-02-03 20:42:28">]
    irb(main):040:0> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:44:17+00:00Added an answer on June 18, 2026 at 5:44 am

    Turns out, I was doing everything right except:

    r = Resource.where(id: 3)
    

    Needs to be

    r = Resource.where(id: 3).first
    

    As the first one returns an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 customer views one for create and one for edit. I am
Is there any external library using which one can edit and save XML files
Edit 4/4/12 I STILL HAVE ONE QUESTION: I solved my issue but it adds
edit: I completely rewrote the question as the original one didn't clearly explain my
I have following function in one Activity public void AppExit() { Editor edit =
On one of my packages, which was adapted from another using Save-As and edit,
EDIT: following the first answer I have looked more into stackoverflow and rephrased the
EDIT: Using the solutions presented below, I have changed the code to have a
I am creating a login register page which contains two edit text boxes(one for
[edit] So I used one of the javascript tooltips suggested below. I got the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.