Rails 3 和载波
我使用 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
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 I can save a picture and a gallery? The following doesn't save the picture:
gallery = params[:gallery].delete(:gallery_pic)
@gallery = Gallery.new(params[:gallery])
@gallery.gallery_pictures << GalleryPicture.new(gallery)
@gallery.save
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您会发现这很有帮助
http://blog.assimov.net /post/4306595758/multi-file-upload-with-uploadify-and-carrierwave-on
您可以在模型
控制器中使用以下内容,应该与从脚手架生成的相同
You can find this helpful
http://blog.assimov.net/post/4306595758/multi-file-upload-with-uploadify-and-carrierwave-on
you can use following in your model
controller should be same as it generate from scaffold