Skip to content

Instantly share code, notes, and snippets.

@mnelson
Created March 19, 2011 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mnelson/877133 to your computer and use it in GitHub Desktop.
Save mnelson/877133 to your computer and use it in GitHub Desktop.
#attached_files
%p.declaration
Attachments:
%em
= add_object_link("add", "#attached_files", {:partial => '/attached_files/file', :locals => {:form => form}})
- object.attached_files.each_with_index do |attachment, i|
= render :partial => '/attached_files/file', :locals => {:form => form, :attached_file => attachment, :child_index => i}
- attached_file ||= AttachedFile.new
%p.attached_file
- if attached_file.new_record?
= form.fields_for 'attached_files_attributes[]', attached_file do |fca|
= fca.file_field :attachment
= fca.hidden_field :nested, :value => true
= link_to_function 'remove', %{jQuery(this).parent('.attached_file').remove();}
- else
= link_to attached_file.name, attached_file.url
def add_object_link(text, where, render_opts)
html = render(render_opts)
link_to_function text, %{var html = jQuery(#{html.to_json});html.appendTo(jQuery(#{where.to_json}));}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment