我认为一切都很好..但它不起作用..
我将整个文件上传到 github
https://github.com/iom00/action2.git
我最近更新了 gem。但是在rails 3.2上也有同样的问题..
请帮帮我~!
投资组合模型
class Portf
include Mongoid::Document
field :title, type: String
field :decs, type: String
attr_accessible :images
embeds_many :images
accepts_nested_attributes_for :images, :allow_destroy => true
end
图像模型
class Image
include Mongoid::Document
include Mongoid::Paperclip
field :portf_id, type: Integer
embedded_in :portf , :inverse_of => :images
has_mongoid_attached_file :file
end
投资组合控制器
# GET /portfs/new
# GET /portfs/new.json
def new
@portf = Portf.new
5.times { @portf.images.build }
respond_to do |format|
format.html # new.html.erb
format.json { render json: @portf }
end
end
# GET /portfs/1/edit
def edit
@portf = Portf.find(params[:id])
5.times { @portf.images.build }
end
形式
<%= form_for @portf, :html => { :multipart => true } do |f| %>
<%= f.fields_for :images do |image| %>
<% if image.object.new_record? %>
<%= image.file_field :file %>
<% end %>
<% end %>