Ruby on rails Rails文件_fieldhelper不';我什么也不退

Ruby on rails Rails文件_fieldhelper不';我什么也不退,ruby-on-rails,paperclip,attachment,simple-form,Ruby On Rails,Paperclip,Attachment,Simple Form,我用的是简单形式。我有一个用于创建新项目的表单,还有一个用于编辑现有项目的表单。我还为每个项目设置了两个文件字段。困扰我的是,文件字段在创建新项目时显示良好,但在编辑现有项目时,它们根本不会生成 我在Rails 3.0中已经完美地实现了这一点,但现在在Rails 3.2.1中无法实现 表格: <%= simple_form_for @item, :html => { :multipart => true } do |f| %> <%= f.input :ti

我用的是简单形式。我有一个用于创建新项目的表单,还有一个用于编辑现有项目的表单。我还为每个项目设置了两个文件字段。困扰我的是,文件字段在创建新项目时显示良好,但在编辑现有项目时,它们根本不会生成

我在Rails 3.0中已经完美地实现了这一点,但现在在Rails 3.2.1中无法实现

表格:

<%= simple_form_for @item, :html => { :multipart => true } do |f| %>
    <%= f.input :title, :input_html => { :maxlength => 35 } %>
    <%= f.input :description, :input_html => { :maxlength => 450 } %>
    <%= f.input :secure_details, :placeholder => "Serial numbers and other stuff that will remain private", :input_html => { :maxlength => 450 } %>
    <%= f.association :bookmark, :collection => current_user.bookmarks(:order => :position), :include_blank => false %>
    <%= f.input :warranty_until, :as => :string, :input_html => { :id =>'datepicker2' } %>
    <div class="image_attachment">
        <div class="attachment_text">
            Update item photo<br />
            <small>(will replace old one)</small>
        </div>
        <div class="attachment_button">
        <% f.fields_for :assets do |asset| %>
            <%= asset.file_field :photo %>
        <% end %>
        </div>
    </div>
    <div class="image_attachment">
        <div class="attachment_text">
            Update receipt<br />
            <small>(will replace old one)</small>
        </div>
        <div class="attachment_button">
        <% f.fields_for :receipts do |receipt| %>
            <%= receipt.file_field :photo %>
        <% end %>
        </div>
    </div>
    <%= f.input :public, :label => "My friends can see this item", :input_html => { :class => "right" } %>
    <%= f.input :giveaway, :label => "Mark as giveaway", :input_html => { :class => "right" } %>
    <div class="margin_r margin_t">
        <%= f.button :submit, :class => 'small_button white right' %>
    </div>

<% end %>
{:multipart=>true}do | f |%>
{:maxlength=>35}%>
{:maxlength=>450}%>
“序列号和其他将保持私有的内容”,:input_html=>{:maxlength=>450}%>
当前用户。书签(:order=>:position),:include\u blank=>false%>
:string,:input_html=>{:id=>'datepicker2'}%>
更新项目照片
(将替换旧的) 更新收据
(将替换旧的) “我的朋友可以看到这个项目”,:input_html=>{:class=>“right”}%> “标记为赠品”,:input_html=>{:class=>“right”}%> '右小按钮白色'%>
基本上,这部分代码不起作用:

<div class="attachment_button">
        <% f.fields_for :assets do |asset| %>
            <%= asset.file_field :photo %>
        <% end %>
</div>

生成的HTML只是空div

同样的代码在创建新项目时有效,但在编辑现有项目时无效

资产和收据都使用回形针存储图像。以下是资产类别的代码:

class Asset < ActiveRecord::Base
    belongs_to :item

    has_attached_file :photo, 
        :styles => {
            :thumb => "80x80#",  
            :small => "150x150>" }
    validates_attachment_size :photo, :less_than => 550.kilobytes
    validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']

end
class资产{
:thumb=>“80x80#”,
:small=>“150x150>”}
验证\u附件\u大小:照片,:小于=>550.KB
验证附件内容类型:照片,内容类型=>['image/jpeg','image/png']
结束

也许您忘了在您的商品模型中添加这行代码:

accepts_nested_attributes_for :receipts, :allow_destroy => true
accepts_nested_attributes_for :assets, :allow_destroy => true
并添加“=”:

<%= f.fields_for :assets do |asset| %>
    <%= asset.file_field :photo %>
<% end %>

<%= f.fields_for :receipts do |receipt| %>
    <%= receipt.file_field :photo %>
<% end %>

谢谢,就是缺少的“=”了!我有点认为它会起作用,但在Rails3.2中,规则似乎更为严格。