【发布时间】:2011-10-16 04:41:24
【问题描述】:
游览has_many :photos,照片belongs_to :tour。
游览的字段是:title, :description。
照片的字段是:alt, :image (path), :tour_id
游览accepts_nested_attributes_for :photos
游览attr_accessible :photo_attributes
--
在旅游的表单中,我想在保存后返回表单中的相应旅游照片,以便用户可以看到他们上传的照片并添加他们的 Alt 标签
这是表单的样子,但我不知道如何将任何保存的图像带回表单...
= semantic_form_for ([:admin, @tour]), :html => {:multipart => true} do |f|
...
- unless @tour.new_record?
= semantic_fields_for Photo.new do |f|
= f.file_field :image, :rel => tour_photos_path(@tour)
- else
You must save the tour, to be able add photos.
= f.semantic_fields_for :photos, @tour.photos do |p|
// If there is a photo, somehow display that image in this form loop...
= image_tag ## WHAT COULD I PUT HERE? ##
= f.input :remove_image, :as => :boolean
= p.inputs
我很困惑,因为很明显 form_helper 可以将保存的表单元素带回表单字段。但我不知道如何使用图像标签中保存的元素之一...
【问题讨论】:
标签: ruby-on-rails-3 nested-attributes form-helpers