Skip to content

Instantly share code, notes, and snippets.

@bhoggard
Created August 1, 2012 17:18
Show Gist options
  • Save bhoggard/3228946 to your computer and use it in GitHub Desktop.
Save bhoggard/3228946 to your computer and use it in GitHub Desktop.
partial for adding additional images
<div class='image'>
<% new_or_existing = image.new_record? ? 'new' : 'existing' %>
<% prefix = "work[#{new_or_existing}_image_attributes][]"%>
<% fields_for prefix, image do |f| %>
<p>
<%= f.label :caption %><br />
<%= f.text_field :caption %>
</p>
<p>
<% if new_or_existing == 'existing' %>
<%= image_tag(image.file.url(:thumb, false)) %><br /><br />
Replace: <%= f.file_field :file %>
<%= link_to_function "remove", "$(this).parent().parent().remove()"%>
<% else %>
File: <%= f.file_field :file %>
<%= link_to_function "remove", "$(this).parent().parent().remove()"%>
<% end %>
<hr style="width: 50%" />
</p>
<% end -%>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment