目前我在用户和照片之间有一个 has_one 关系。
User model:
has_one :photo
accepts_nested_attributes_for :photo
Photo model:
belongs_to :user
Paperclip.options[:command_path] = "/usr/local/bin"
has_attached_file :image,
:path => ':rails_root/public/images/ads/:id/:basename.:extension',
:url => "images/ads/:id/:basename.:extension"
嵌套形式:
<%= f.simple_fields_for :photo_attributes, :html => { :multipart => true } do |d| %>
<%= d.input :billed_navn %>
<%= d.label :image, :label => 'Upload logo', :required => false %>
<%= d.file_field :image, :label => 'Image', :class => 'imagec', :required => 'false', :style => 'margin-bottom:2px;float:left;width:250px;' %>
<input type="button" value="Clear" id="clear" style="width:70px;float:left;margin-right:2px;">
<%= d.input :image_url, :label => 'Billed URL', :input_html => { :class => 'imagec'}, :required => false %>
<%= f.label :image, :label => 'Billed preview', :required => false %><div id="preview"></div>
<% end %>
此设置正常工作,我可以上传 1 张照片。我的用户能够一次上传多张照片。
因此,我已将 useres 模型中的关联更改为:
User model:
has_many :photos
accepts_nested_attributes_for :photos
但是我应该如何嵌套形式呢?如果应该可以一次上传多个图像?