Rails 3 and the carrier wave

I use Rails 3 and Carrierwave. I have two models: Gallery and GalleryPicture :

 class Gallery < ActiveRecord::Base has_many :gallery_pictures end class GalleryPicture < ActiveRecord::Base belongs_to :gallery mount_uploader :gallery_pic, GalleryUploader end 

How can I save image and gallery? The following snapshot does not save:

 gallery = params[:gallery].delete(:gallery_pic) @gallery = Gallery.new(params[:gallery]) @gallery.gallery_pictures << GalleryPicture.new(gallery) @gallery.save 
+4
source share
1 answer

You can find this useful http://blog.assimov.net/post/4306595758/multi-file-upload-with-uploadify-and-carrierwave-on

you can use the following in your model

 class Gallery < ActiveRecord::Base has_many :gallery_pictures, :dependent => :destroy accepts_nested_attributes_for :gallery_pictures end class GalleryPicture < ActiveRecord::Base belongs_to :gallery mount_uploader :gallery_pic, GalleryPicUploader end <% form_for @gallery %> <fields> <%= f.fields_for :gallery_pictures do |builder| %> <% end %> <% end %> 
Controller

should be the same as with the sketch

+2
source

All Articles