我使用Rails 3和Carrierwave。我有两个模型:Gallery
和GalleryPicture
:
class Gallery < ActiveRecord::Base
has_many :gallery_pictures
end
class GalleryPicture < ActiveRecord::Base
belongs_to :gallery
mount_uploader :gallery_pic, GalleryUploader
end
我该如何保存图片和相册?以下代码不能保存图片:
gallery = params[:gallery].delete(:gallery_pic)
@gallery = Gallery.new(params[:gallery])
@gallery.gallery_pictures << GalleryPicture.new(gallery)
@gallery.save