Note that there are some explanatory texts on larger screens.

plurals
  1. POPaperclip updating database with NULLS for filename, filesize, etc in Rails3
    primarykey
    data
    text
    <p>I'm attempting to implement Paperclip in my Rails3 app and using Emerson Lackey's railscast (http://www.emersonlackey.com/article/paperclip-with-rails-3) as a model as its very similar to what I am looking to do (have multiple photos for a particular model). However, I'm not getting any of the children objects to save anything other than NULLS about the images.</p> <p>Here is the parent model, cars, which have multiple car photos:</p> <pre><code>class Car &lt; ActiveRecord::Base attr_accessible :model_year, :admin_model_name_id, :chassis_number, :location, :description, :for_sale, :sale_contact_info_visible_to_all, :sale_contact_number, :car_photos_attributes has_many :car_photos, :dependent =&gt; :destroy accepts_nested_attributes_for :car_photos, :allow_destroy =&gt; true </code></pre> <p>And then the model for the car photo:</p> <pre><code>class CarPhoto &lt; ActiveRecord::Base belongs_to :car has_attached_file :car_photo, :styles =&gt; { :large =&gt; "640x480", :medium =&gt; "300x300&gt;", :thumb =&gt; "100x100&gt;" } attr_accessible :file_name, :content_type, :file_size, :car_id end </code></pre> <p>Upon saving a new car, the Car saves fine as before but the CarPhotos do not. Here is the output from webrick:</p> <pre><code>AREL (0.2ms) INSERT INTO `car_photos` (`file_name`, `content_type`, `file_size`, `car_id`, `created_at`, `updated_at`) VALUES (NULL, NULL, NULL, 38, '2011-03-10 17:15:52', '2011-03-10 17:15:52') [paperclip] Saving attachments. [paperclip] Saving attachments. SQL (5.8ms) COMMIT Redirected to http://127.0.0.1:3000/cars/38 Completed 302 Found in 144ms </code></pre> <p>I expect that this has something to do with the attr_accessible macros in the two models but I have not been able to determine exactly what it is. Emerson's source code has no changes from the scaffolding for the create method so not sure if I need to update mine to get the children to save the values from the form. I do have the :html => { :multipart => true } in my form_for @car in my view. Clues? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    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