I'm tryi开发者_高级运维ng 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!
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.
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
This has now been fixed in version 2.3.3 of paperclip. See this commit: https://github.com/thoughtbot/paperclip/commit/1bcfc14388d0651c5fc70ab9ca3511144c698903
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.
精彩评论