Created
May 18, 2012 19:23
-
-
Save felipemesquita/2727176 to your computer and use it in GitHub Desktop.
This file contains 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
<%= simple_form_for(@project) do |project_form| %> | |
<ul id="goals"> | |
<%= project_form.simple_fields_for :goals do |goal_form| %> | |
<%= render 'goal_form', :goal_form => goal_form %> | |
<% end %> | |
</ul> | |
<% end %> |
This file contains 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
<% el_id = goal_form.object.new_record?? 'NEW_RECORD' : goal_form.object.object_id %> | |
<li id="<%= el_id %>"> | |
<%= goal_form.input :name %> | |
</li> |
This file contains 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
class Project < ActiveRecord::Base | |
has_many :goals, :dependent => :destroy | |
accepts_nested_attributes_for :goals, :allow_destroy => true | |
end |
This file contains 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
function add_goal(html_form) { | |
$('#goals').append( html_form.replace(/NEW_RECORD/g, new Date().getTime()) ); | |
} |
This file contains 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_goal_link(form_builder) | |
html = nil | |
form_builder.fields_for :goals, Goal.new, :child_index => 'NEW_RECORD' do |goal_form| | |
html = render('goal_form', :goal_form => goal_form ) | |
end | |
link_to_function t('interface.add_goal'), "add_goal('#{escape_javascript(html)}')" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment