旅游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 可以将表单的已保存元素带回表单字段中。但我不知道如何在图像标签中使用其中一个已保存的元素...