views:

895

answers:

3

I'm trying to write a rails application where users can upload images, but Paperclip doesn't seem to be working for me.

I've gone through all the basic steps (added has_attached_file, the migration, making the form multipart) but I keep getting the same error whenever I try uploading an image:

can't convert nil into Integer

Looking at the top of the stack

...rails3/lib/paperclip/processor.rb:46:in `sprintf'

...rails3/lib/paperclip/processor.rb:46:in `make_tmpname'

.../ruby-1.9.2-head/lib/ruby/1.9.1/tmpdir.rb:154:in `create'

.../ruby-1.9.2-head/lib/ruby/1.9.1/tempfile.rb:134:in `initialize'

It seems the problem is in the tempfile.

My code:

_form.rb

<%= form_for @high_school, :html => {:multipart => true} do |f| %>
  <%= f.error_messages %>
  ...
  <div class="field">
    <%= f.file_field :photo %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

model/high_school.rb

...
validates_length_of :password, :minimum => 4, :allow_blank => true
has_attached_file :photo
has_many :students
...

Is this a known problem? I basically followed the instructions from the github to the letter.

My environment: Rails3 and Ruby 1.9.2dev

Thank you!

+1  A: 

I don't believe paperclip supports ruby 1.9 yet.

Try dropping down to ruby 1.8.7 and see if the problem still exists.

jrallison
That's unfortunate. Oh well.
Eric Koslow
It indeed solves the problem but this is not a good solution. Did anyone tried the solution from kiew?
Cimm
A: 

Here somebody has similar problem to yours with Paperclip on ruby 1.9 (but there is no solution). So probably it is problem with ruby version.

klew
+1  A: 

you have to apply this patch http://github.com/dwalters/paperclip/commit/2a85add5f102db8773518f8ac30f7e2337bf7d13 to get paperclip working on 1.9.2 head for the can't convert nil into Integer error

zak