Note that there are some explanatory texts on larger screens.

plurals
  1. PORails: paperclip does not save in database
    primarykey
    data
    text
    <p>So I just added paperclip and migrated it to a table called users_pictures. My Model looks like this:</p> <pre><code>class UsersPicture &lt; ActiveRecord::Base attr_accessible :user_id, :users_picture_file, :users_picture_id, :photo_file_name, :photo_content_type, :photo_file_size belongs_to :users has_attached_file :photo, :url =&gt; "/images/:attachment/:basename.:extension", :path =&gt; ":rails_root/public/images/:attachment/:basename.:extension" end </code></pre> <p>So when I am accessing the "new.html.erb" page, I can add a picture to the form ... give it the user_id and submit. Rails does not show me any errors and the log even says:</p> <pre><code>Processing by UsersPicturesController#create as HTML Parameters: {"commit"=&gt;"Create Users picture",` "authenticity_token"=&gt;"0tbAZj5MKyN/uaj0ybaNsa0dZrxeS05OJNNA3ZNO8Uc=", "users_picture"=&gt;{"user_id"=&gt;"12", "photo"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0xe028dbd4 @content_type="image/jpeg", @tempfile=#&lt;File:/tmp/RackMultipart20121019-14239-1edlwpp-0&gt;, @headers="Content-Disposition: form-data; name=\"users_picture[photo]\"; filename=\"rh.jpeg \"\r\nContent-Type: image/jpeg\r\n", @original_filename="rh.jpeg"&gt;}, "utf8"=&gt;"✓"} [paperclip] Saving attachments. Redirected to xxxx/users_pictures/8 Completed 302 Found in 18ms (ActiveRecord: 1.2ms) </code></pre> <p>But the fileinfo is not being saved into database ... so I cannot display it. Firebug tells me something about the parameters for the POST method:</p> <pre><code>authenticity_token 0tbAZj5MKyN/uaj0ybaNsa0dZrxeS05OJNNA3ZNO8Uc= users_picture[user_id] 12 users_picture[photo] ÿØÿà�JFIF������ÿÛ�� !"&amp;# /!$'),,-180*5*+,) 0%"5)-,*4,,,*,),),,,,,,,,,,,,,))),,,*,),,,,),),,,)).,ÿÀ��Ì�Ì"�ÿÄ��������������ÿÄ�E� ����!1AQ"aq2#BRbr¡3²¢±ÁÑ4SÓ%Cs£ÒáÿÄ������������ÿÄ�%��������!1"A2BQq¡ÿÚ���?�Þ4¥()JJRR ¥pLªXl °ôR|¨u]Þýú </code></pre> <p>And so on. So it is not saving the path into the database but the sourcecode of the picture? As you can see, I already set :url and :path (even without the :attachment because I don't know what it is)</p> <p>In general, I just wanted to upload pictures to a certain path; and store the file information like name and size in my database.</p> <p>My form from the view-folder looks like this:</p> <pre><code>&lt;%= form_for(@users_picture, :html =&gt; { :multipart =&gt; true }) do |f| %&gt; ... &lt;%= f.file_field :photo %&gt; </code></pre> <p>I will not post the show and index.html.erb because displaying is another thing - I first have to achieve to save all the data in the database + upload the pictures to certain folders. Any advice on how to do it correctly ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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