Note that there are some explanatory texts on larger screens.

plurals
  1. POrails 3, paperclip assigns id 0 when uploading image
    text
    copied!<p>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. </p> <p>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!</p> <pre><code>#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 </code></pre> <p>i tried to add attr_accessible to my model</p> <pre><code>attr_accessible :logo_file_name, :logo_content_type, :logo_file_size, :logo_updated_at </code></pre> <p>but that throws me an sql-error</p> <p>Column 'logo_file_size' cannot be null</p> <p>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...</p> <p>my code:</p> <p>MODEL:</p> <pre><code>has_attached_file :logo, :url =&gt; "/:class/:attachment/:id/:basename.:extension", :styles =&gt; { :original =&gt; ["150x150&gt;", :png] } </code></pre> <p>VIEW:</p> <pre><code>&lt;%= f.inputs do %&gt; &lt;%= f.input :name %&gt; &lt;%= f.input :logo, :as =&gt; :file %&gt; &lt;%= f.input :link, :as =&gt; :url %&gt; &lt;%= f.input :published, :published =&gt; 'Veröffentlicht' %&gt; &lt;% end %&gt; </code></pre> <p>CONTROLLER:</p> <pre><code>def create Article.create(params[:article]) end </code></pre> <p>my datebase has these 4 colums in Article-Table: logo_file_name logo_content_type logo_file_size logo_updated_at</p> <p>iam using rails 3.1.1, formtastic 1.2.4, paperclip 2.4.5</p> <p>thanks a lot for your help!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload