Created
March 19, 2011 01:35
-
-
Save mnelson/877133 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
#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} |
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
- 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 |
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
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