使用Paperclip在ror中多次上传

我正在使用回形针为一栋建筑上传一张照片。 http://www.youtube.com/watch?v=KGmsaXhIdjc我用这种方式完成了它。 但我知道我决定将许多照片上传到一栋建筑物。 我可以用回形针做到这一点,还是必须改变它并使用jQuery? 如果我能怎么样? Ps:如果需要,我会上传我的代码。 ps:我想在照片2和照片3的数据库中再制作2列 。顺便说一下,我看到所有产生的资产都是为了做到这一点。 我认为我用不同的方式上传1张照片。 这意味着我必须改变一切吗?

更新1:

在routes.rb中

resources :buildings do resources :photos end 

在buldings> _form

 {:multipart => true}) do |f| %>  

prohibited this building from being saved:



'Select status of the building' %>

10 %>

<!--
-->

在模型>建筑

  attr_accessible :description, :price, :status, :title, :photo accepts_nested_attributes_for :photo, :allow_destroy => true has_attached_file :photo , :url => "/assets/products/:id/:style/:basename.:extension", :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension" 

是的,你可以用回形针做到这一点。 我这样做的方式是使用嵌套资源和nested_form gem。

例如,您building has_many :photosphoto belongs_to :building

然后在/views/buildings/_form.html.erb你会写这样的东西:

 <%= nested_form_for @building, :html => { :multipart => true } do |f| %> <%# all your building fields .... %> <%= f.fields_for :photos do |photo| %> <% if photo.object.new_record? %> <%= photo.file_field(:image) %> <% else %> <%= image_tag(photo.url(:thumb)) %> <%= photo.hidden_field :_destroy %> <%= photo.link_to_remove "X" %> <% end %> <% end %> 

<%= f.link_to_add "Add photo", :photos %>

<%= f.submit %> <% end %>

您必须在building.rb模型中设置accepts_nested_attributes_for :photos, :allow_destroy => true ,并确保您的routes.rb还包含嵌套:

 resources :buildings do resources :photos end