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

  • SEARCH
  • Home
  • 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 7173025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:44:18+00:00 2026-05-28T15:44:18+00:00

I am having an issue I have yet to see elsewhere using the image

  • 0

I am having an issue I have yet to see elsewhere using the image cropping from this railscast

It’s on my production app, and I am only getting this exception every once and a while, and I haven’t been able to reproduce it myself locally.

The error:

PhotosController# (ActionView::Template::Error) "can't convert nil into String"

/app/.bundle/gems/ruby/1.9.1/gems/paperclip-2.3.15/lib/paperclip/storage/s3.rb:163:in `extname'
/app/.bundle/gems/ruby/1.9.1/gems/paperclip-2.3.15/lib/paperclip/storage/s3.rb:163:in `to_file'
/app/app/models/photo.rb:27:in `photo_geometry'
/app/app/views/photos/show.html.erb:17:in `block in _app_views_photos_show_html_erb__1949294035370253936_41955540__272030757437175302'

photo.rb

  def cropping?  
    !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?  
  end

  def photo_geometry(style = :original)  
    @geometry ||= {}  
    @geometry[style] ||= Paperclip::Geometry.from_file(photo.to_file(style))  # line #27
  end

show.html.erb

<% content_for(:head) do %>
    <%= stylesheet_link_tag "jquery.Jcrop" %>
    <%= javascript_include_tag "jquery.Jcrop.min" %>
    <script type="text/javascript" charset="utf-8">
        $(function() {
        $('#cropbox').Jcrop({
                onChange: update_crop,  
                onSelect: update_crop,  
                setSelect: [0, 0, 90, 90],  
                aspectRatio: 1
            });
            function update_crop(coords) {
                var rx = 100/coords.w;  
                  var ry = 100/coords.h;  
                  $('#preview').css({  
                    width: Math.round(rx * <%= @photo.photo_geometry(:large).width %>) + 'px',  // line #17
                    height: Math.round(ry * <%= @photo.photo_geometry(:large).height %>) + 'px',  
                    marginLeft: '-' + Math.round(rx * coords.x) + 'px',  
                    marginTop: '-' + Math.round(ry * coords.y) + 'px'  
                  });

              var ratio = <%= @photo.photo_geometry(:original).width %> / <%= @photo.photo_geometry(:large).width %>;   
                  $('#crop_x').val(Math.floor(coords.x * ratio));  
                  $('#crop_y').val(Math.floor(coords.y * ratio));  
                  $('#crop_w').val(Math.floor(coords.w * ratio));  
                  $('#crop_h').val(Math.floor(coords.h * ratio));  
            }
        });
    </script>
<% end %>

I’m guessing the issue has something to do with paperclip being unable to grab the dimensions of the uploaded photo, but frankly I don’t understand the photo.rb code very well, I just copied it directly from the railscast.

Any ideas? If someone could explain what is going on in photo.rb a bit better I would appreciate it.

Thanks!

  • 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-05-28T15:44:19+00:00Added an answer on May 28, 2026 at 3:44 pm

    Could it be that the problem has to do with files without an extension?

    For instance when you allow people to give an URL for an image to use on your service and you download that image for conversion and storage on S3 it could be the download does not have an extension, while it does have a content type and therefore is displayed and processed correctly as an image.

    The problem occurs here: (See comments)

     def to_file style = default_style
        return @queued_for_write[style] if @queued_for_write[style]
        filename = path(style)
        extname  = File.extname(filename)           # Likely the Nil is returned here
        basename = File.basename(filename, extname)
        file = Tempfile.new([basename, extname])    # Ext name is used here
        file.binmode
        file.write(AWS::S3::S3Object.value(path(style), bucket_name))
        file.rewind
        return file
      end
    

    You can try the following monkey patch if the extension indeed causes the Nil:

    module Paperclip
      module Storage
        module S3
          def to_file style = default_style
            return @queued_for_write[style] if @queued_for_write[style]
            filename = path(style)
            extname  = File.extname(filename) || ""          # <==== Changed
            basename = File.basename(filename, extname)
            file = Tempfile.new([basename, extname])   
            file.binmode
            file.write(AWS::S3::S3Object.value(path(style), bucket_name))
            file.rewind
            return file
          end
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having this issue in iterating through an array of keys and
I'm having an issue bending my head around this one. I have a table
I'm having an issue getting a LINQ query to work. I have this XML:
I'm having an issue that apparently many people have had as well, only what
I'm having this issue that I've yet to find a solution to. For example,
I'm having an odd issue in FF10 using jQuery 1.7.1. I have a gallery
Having an issue here that I have tried everything I can think of but
I'm having an issue with multiple markers on google maps - I currently have
I am having an issue with ColdFusion's CFChart tag. I have a couple graphs
I am having following issue with reading binary file in C. I have read

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.