Created
November 22, 2011 02:46
-
-
Save zorn/1384743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _form.html.erb | |
<%= f.fields_for :file_attachments do |builder| %> | |
<%= render 'file_attachment_fields', :f => builder %> | |
<% end %> | |
# _file_attachment_fields.html.erb | |
<div class="clearfix fields"> | |
<label>Name:</label> | |
<div class="input"> | |
<%= f.text_field :name %> | |
<%= f.file_field :attachment %> | |
<%= f.hidden_field :_destroy %> | |
<%= link_to_function "Remove", "remove_fields(this)" %> | |
</div> | |
</div> | |
# So what I'd like to do is make the partial something like: | |
<div class="clearfix fields"> | |
<label>Name:</label> | |
<div class="input"> | |
<%= f.text_field :name %> | |
<% if @file_attachment.new? %> | |
<%= f.file_field :attachment %> | |
<% else %> | |
<a href="<%= @file_attachment.attachment.url %>"><%= @file_attachment.attachment_file_name %></a> | |
<% end %> | |
<%= f.hidden_field :_destroy %> | |
<%= link_to_function "Remove", "remove_fields(this)" %> | |
</div> | |
</div> | |
# But using fields_for and passing in a collection | |
# I'm unsure how I can access the current object | |
# (ala @file_attachment) in the iteration. |
I did not know about f.object. Seems to work. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and f.object doesn't work?