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.
Here is the parent model, cars, which have multiple car photos:
class Car < 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 => :destroy
accepts_nested_attributes_for :car_photos, :allow_destroy => true
And then the model for the car photo:
class CarPhoto < ActiveRecord::Base
belongs_to :car
has_attached_file :car_photo, :styles => { :large => "640x480", :medium => "300x300>", :thumb => "100x100>" }
attr_accessible :file_name, :content_type, :file_size, :car_id
end
Upon saving a new car, the Car saves fine as before but the CarPhotos do not. Here is the output from webrick:
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
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.