Skip to content

Instantly share code, notes, and snippets.

@jerodsanto
Created October 25, 2010 15:56
Show Gist options
  • Save jerodsanto/645188 to your computer and use it in GitHub Desktop.
Save jerodsanto/645188 to your computer and use it in GitHub Desktop.
document_helper.rb
- f.semantic_fields_for :contributions, obj, :child_index => i do |child_form|
= child_form.input :person_id, :collection => Person.all.collect { |p| [p.name, p.id]}, :include_blank => false, :label => 'Contributor Name'
= child_form.input :name, :label => 'Type'
- semantic_form_for @document, :html => {:multipart => true} do |f|
- f.inputs do
= f.input :tag_list
%li.tags
%label available tags
= tag_collection_select
= f.input :doctype, :collection => Document::Types, :include_blank => false, :label => "Type"
= f.input :title
= f.input :short_name, :required => false
= f.input :published_on
#contributors
- @document.contributions.each do |c|
- unless c.new_record?
.nested
- f.semantic_fields_for :contributions, c do |child_form|
= child_form.label c.name
= c.person.name + " " + link_to('[X]', '#', :class => 'remove')
= child_form.input(:_destroy, :as => :hidden)
%li
%label  
= add_contribution_link(f,@document)
= f.input :cost, :required => false
module DocumentHelper
def add_contribution_link(f,doc)
link_to_function "Add Contributor" do |page|
html = render 'contribution_fields', :f => f, :obj => doc.contributions.build, :i => 'NEW'
page << "$('#contributors').append('#{escape_javascript(html)}'.replace(/NEW/g, new Date().getTime()));"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment