1

我有一个项目模型:

class Project < ActiveRecord::Base
  attr_accessible :active, :address, :date_begun, :date_ended, :description, :name, :url, :organization_id, :invisible, :zone, :definition, :images, :partners, :external_partners, :partner_ids, :external_partner_ids, :images_attributes 

  has_many    :images, :as => :imageble

  accepts_nested_attributes_for :images

end

图像多态模型

class Image < ActiveRecord::Base
  attr_accessible :imageble_id, :imageble_type, :order, :data

  belongs_to :imageble, :polymorphic => true

  has_attached_file :data, 
  :styles => { :mini => "60x60#", :medium => "300x300>", :thumb => "100x100>" }, 
  ...
end

项目控制器:

class Admin::ProjectsController < ApplicationController
  def edit
    @project = Project.find(params[:id])
    @project.images.build
    @hash_partners = Organization.retrieve_hash(@project.partners.collect{|o| o.id})
    @hash_external_partners = ExternalOrganization.retrieve_hash(@project.external_partners.collect{|eo| eo.id})
  end
end

以及项目的表格形式:

<%= semantic_form_for ([:admin, @project]) do |f| %>
<%= f.inputs do %>
  <%= f.input :name,         :label =>"Nome",    :hint => "Clicca sul nome per cambiare", :placeholder => "nome del progetto" %>

  <%= f.semantic_fields_for :images do |images| %>
     <%= images.inputs :data %>
  <% end %>

  <% @project.images.each do |i| %>
     <%= image_tag i.data(:mini) %>
  <% end  %>

<% end %>
<%= f.actions %>
<% end %>

一切正常,但是当我向项目添加图像时,表单会向表单呈现越来越多的文件输入按钮。

我想要的是只有一个文件上传按钮来向项目添加新图像。然后有一个项目图像缩略图列表。

如何在 Rails3 和 Formtastic 2.1.1 中实现这一点?

4

0 回答 0