나는 게으니까 Ryan Bates Nested_Form 보석을 좋아합니다. 그러나 나는 그런 의견에 관해서
<div class="clearfix">
<%= f.file_field :image %>
</div>
부분 _photo.erb이
<%= semantic_nested_form_for @user, :html => {:multipart => true} do |f| %>
<%= f.fields_for :photo %>
<p><%= f.link_to_add "Add Photo", :photo %></p>
<div class="actions">
<%= f.submit :class => "btn-success" %>
</div>
<% end %>
을 할 거라고 :
을 나는 이것이 당신이, 내가 해냈어 찾고있는 것을 생각 여기 (Railscast의 carrierwave 에피소드 기준) :
https://github.com/rbirnie/image-upload
기본 소스 :
갤러리 모델
class Gallery < ActiveRecord::Base
attr_accessible :name, :paintings_attributes
has_many :paintings
accepts_nested_attributes_for :paintings
end
회화 모델 :
class Painting < ActiveRecord::Base
attr_accessible :gallery_id, :name, :image, :remote_image_url
belongs_to :gallery
mount_uploader :image, ImageUploader
end
갤러리 편집
<%= nested_form_for @gallery, :html => {:multipart => true} do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<%= f.fields_for :paintings do |photo_form| %>
<%= photo_form.label :name %>
<%= photo_form.text_field :name %>
<%= photo_form.file_field :image %>
<%= photo_form.link_to_remove "Remove this photo" %>
<% end %>
<p><%= f.link_to_add "Add a photo", :paintings %></p>
<p><%= f.submit %></p>
<% end %>
~ 나는 여러 파일을 plupload를 사용하여 종료
나는 이것이 내가 무엇을 찾고 있는지 확신하지 못한다. 나는 그걸 가지고 놀고 있었고 작동시키지 못했다. 기본적으로 두 가지 모델에 대해 두 가지 다른 작업을 수행하려고합니다. has_many 사진이있는 User 모델을 업데이트하고 두 개의 새 사진 개체를 만들고 싶습니다. 코드를 사용할 때 새 Photo.rb 객체를 만들지 않고 사용자와 기존 사진을 모두 업데이트했습니다. – kcurtin