我正在做一个大的嵌套表单,用户可以为每个嵌套表单上传一张图片。但我有一个疑问。我如何向用户显示,当他编辑表单时,如果已经有图像上传到每个嵌套表单?我想在文件加载器输入旁边显示图像文件名,但我不知道该怎么做。
这是我的代码:
模型
class Chapter < ActiveRecord::Base
attr_accessible :content, :reference, :story_id, :image, :decisions_attributes
mount_uploader :image, ImageUploader
end
看法
<%= simple_form_for(@story) do |f| %>
<%= f.simple_fields_for :chapters do |builder| %>
<%= render "chapters_fields", f: builder %>
<% end %>
<p>
<%= link_to_add_fields "Add chapters", f, :chapters, "chapters" %>
</p>
<% end %>
形成部分
<div class="chapter-fields">
<h3>Chapter</h3>
<p>
<%= f.input :reference %>
<%= f.input :content, as: :text, input_html: { rows: 10, style: 'width: 100%' } %>
<%= f.input :image %>
<%= f.image_url %>
</p>
<div>
<%= f.simple_fields_for :decisions do |builder| %>
<%= render "decisions_fields", f: builder %>
<% end %>
<%= link_to_add_fields "Add decisions", f, :decisions, "decisions" %>
</div>
<p><%= link_to_remove_fields "Remove chapter", f, "chapter" %></p>
</div>