I'm getting started with Paperclip and can't figure out something: why isn't this form showing up?
in 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 %>
What gets rendered in a browser:
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_a开发者_开发问答t:
attachment_updated_at:
changed_attributes: {}
destroyed: false
marked_for_destruction: false
new_record: true
previously_changed: {}
readonly: false
(When the debug isn't present, only "New Source Form" shows up.
Wow, I can't believe this is happening.
The line <% form_for(@source, :html => { :multipart => true }) do |f| %> should be <%= form_for(@source, :html => { :multipart => true }) do |f| %> (with an equals sign).
This bug took me forEVER to figure out.
Why doesn't RoR give me a warning or something?! Can someone give me some tips to help prevent this from happening again?
This is no bug, since the form is something you actually want to have displayed. Glad, that you found it out on your own ;-)
精彩评论