gpt4 book ai didi

ruby-on-rails - Rails 3 和载波

转载 作者:行者123 更新时间:2023-12-03 15:51:03 25 4
gpt4 key购买 nike

我使用 Rails 3 和 Carrierwave。我有两个型号:GalleryGalleryPicture :

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

最佳答案

你会发现这很有帮助
http://blog.assimov.net/post/4306595758/multi-file-upload-with-uploadify-and-carrierwave-on

您可以在模型中使用以下内容

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 应该和它从脚手架生成的一样

关于ruby-on-rails - Rails 3 和载波,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6386473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com