Search code examples
ruby-on-rails-3paperclipformtastic

rails 3, paperclip assigns id 0 when uploading image


iam using rails with formtastic for my admin backend. i want to be able to upload an image to my recordset, and i try to use paperclip to to that.

when i edit a recordset, the upload of the image works just fine. when i try to CREATE a NEW recordset, paperclip seems to assign the ID 0 for that image in my upload path!

#expected path for new image:
/public/logos/2342/some_image.png


#and thats what i get when i create my new record-set:
/public/logos/0/some_image.png

i tried to add attr_accessible to my model

attr_accessible :logo_file_name, :logo_content_type, :logo_file_size, :logo_updated_at

but that throws me an sql-error

Column 'logo_file_size' cannot be null

EDIT: solved the mysql error when i add attr_accessible. i just allowed the logo_file_size to be null. but the id=0 problem still exists...

my code:

MODEL:

has_attached_file :logo, 
              :url => "/:class/:attachment/:id/:basename.:extension", 
              :styles => { :original => ["150x150>", :png] }

VIEW:

<%= f.inputs do %>
    <%= f.input :name %>
    <%= f.input :logo, :as => :file %>
    <%= f.input :link, :as => :url %>
    <%= f.input :published, :published => 'Veröffentlicht' %>
<% end %>

CONTROLLER:

def create
  Article.create(params[:article])
end

my datebase has these 4 colums in Article-Table: logo_file_name logo_content_type logo_file_size logo_updated_at

iam using rails 3.1.1, formtastic 1.2.4, paperclip 2.4.5

thanks a lot for your help!!!


Solution

  • i know its a bit late, but i found the problem and will share the answer for everyone with the same problem.

    problem was mysql, upgraded to mysql2 gem, and everything worked as expected