为什么这个Ruby on Rails / Paperclip表单不显示?

时间:2011-06-19 19:10:41

标签: ruby-on-rails forms paperclip

我开始使用Paperclip并且无法弄明白:为什么这个表单不显示?

<_>在sources_controller.rb中

class SourcesController < ApplicationController

  def new
    @source = Source.new
    @title = "New Source"
  end

end

in new.html.erb

New Source Form

<%= debug(@source) %>

<% form_for(@source, :html => { :multipart => true }) do |f| %>
  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :attachment %><br />
    <%= f.file_field :attachment %>
  </div>
  <div class="field">
    <%= f.submit 'Create' %>
  </div>
<% end %>

在浏览器中呈现的内容:

New Source Form

--- !ruby/object:Source 
aggregation_cache: {}

association_cache: {}

attributes: 
  attachment_file_name: 
  name: 
  attachment_file_size: 
  attachment_content_type: 
  created_at: 
  parent_asset_id: 
  updated_at: 
  is_directory: 
  id: 
  user_id: 
  attachment_updated_at: 
  access_token: 
attributes_cache: 
  created_at: 
  updated_at: 
  attachment_updated_at: 
changed_attributes: {}

destroyed: false
marked_for_destruction: false
new_record: true
previously_changed: {}

readonly: false

(当调试不存在时,只显示“新源表单”。

2 个答案:

答案 0 :(得分:0)

哇,我无法相信这种情况正在发生。

行&lt;%form_for(@ source,:html =&gt; {:multipart =&gt; true})do | f | %GT;应该是&lt;%= form_for(@ source,:html =&gt; {:multipart =&gt; true})do | f | %GT; (等号)。

这个错误让我想不起来。

为什么RoR没有给我一个警告或什么?!有人可以给我一些提示,以帮助防止再次发生这种情况吗?

答案 1 :(得分:0)

这不是错误,因为表单是您实际想要显示的内容。很高兴,你自己发现了它; - )