昨天我做了回形针多个上传画廊。今天我想自定义这一切,我需要制作一个按钮,点击后添加一个文件上传字段。您可以在此视频中看到示例:http: //www.emersonlackey.com/article/rails-paperclip-multiple-file-uploads 28:27。
我在谷歌搜索过,但找不到任何东西。
@post 表格:
<% form_for @post, :html => {:multipart => true} do |t| %>
<p>
<%= t.label :title, 'Virsraksts:' %></br>
<%= t.text_field :title %></br>
</p>
<p>
<%= t.label :content, 'Teksts:' %>
<%= t.text_area :content, :class => "mceEditor"%>
</p>
<p>Pievienot jaunas bildes:</p>
<%= f.link_to_add "Add a task", :assets %>
<%= f.fields_for :assets do |asset_fields| %>
<% if asset_fields.object.new_record? %>
<%= asset_fields.file_field :asset %>
<%= asset_fields.link_to_remove "Noņemt" %>
<% end %>
<% end %>
<p>
<%= f.fields_for :assets do |asset_fields| %>
<% unless asset_fields.object.new_record? %>
<p>
<%= link_to image_tag(asset_fields.object.asset.url(:thumb)), asset_fields.object.asset.url(:original) %>
<%= asset_fields.check_box :_destroy %>
</p>
<% end %>
<% end %>
</p>
<%= t.submit %>
@post 模型:
class Post < ActiveRecord::Base
attr_accessible :title, :content, :assets_attributes
has_many :assets
accepts_nested_attributes_for :assets, :allow_destroy => true
end
@资产模型:
class Asset < ActiveRecord::Base
belongs_to :post
has_attached_file :asset, :styles => { :large => "640x480", :medium => "300x300>", :thumb => "100x100>" },
:url => "/assets/albums/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/albums/:id/:style/:basename.:extension"
accepts_nested_attributes_for :post, :allow_destroy => true
end