4
我使用Rails 3和Carrierwave。我有兩個型號:Gallery
和GalleryPicture
:Rails 3和Carrierwave
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