我正在处理我的第一个rails应用程序,我正在尝试在表单中设置多个图像上传 . 我创建了一个有很多参赛作品的比赛,参赛作品可以有很多图像 . 我有比赛条目工作,但我无法获得表格的图像上传部分工作 . 我正在关注来自运营商wave wiki的本教程http://lucapette.com/rails/multiple-files-upload-with-carrierwave-and-nested_form/ .

比赛入场模式

class ContestEntry < ActiveRecord::Base
  attr_accessible :body, :title, :contest_id, :entry_images_attributes
  validates :user_id, presence: true
  validates :title, presence: true, length: { maximum: 140 }
  validates :body, presence: true
  validates :contest_id, presence: true

  belongs_to :contest
  belongs_to :user

  has_many :entry_images, as: :imageable

  accepts_nested_attributes_for :entry_images
end

入门图像模型

class EntryImage < ActiveRecord::Base
  attr_accessible :alt, :image_path

  belongs_to :imageable, :polymorphic => true

  validates :image_path, presence: true

  mount_uploader :image, ImageUploader
end

新的报名表

<%= nested_form_for([:contest, @entry], :html => {:multipart => true}) do |f| %>
    <%= render 'shared/error_messages', object: f.object %>
    <%= f.hidden_field :contest_id %>
    <p>
        <%= f.label :title %>
<%= f.text_field :title %> </p> <p> <%= f.label :body %><br> <%= f.text_area :body %> </p> <%= f.fields_for :entry_images do |builder| %> <p> <%= builder.label :alt %>
<%= builder.text_field :alt %> </p> <p> <%= builder.label :image_path %>
<%= builder.file_field :image_path %> </p> <% end %> <p><%= f.link_to_add "Add Image", :entry_images %></p> <%= f.submit "Enter", class: "btn btn-large btn-primary" %> <% end %> <%= javascript_include_tag :defaults,"nested_form" %>

由于某种原因,<%= f.fields_for:entry_images do | builder |中没有显示任何内容%>块 . 它只是空白,也没有错误信息 . 如果我将它切换到<%= f.fields_for:entry_image do | builder | %>并切换到使用form_for而不是nested_form_for插件所有字段显示但我提交时出错 .

有任何想法吗?

谢谢,科里