Created
June 1, 2010 21:41
-
-
Save stefanoverna/421546 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
# views/resources/new.html.haml | |
= form_for @resource do |form| | |
= form.fields_for :fields do |field_form| | |
render :partial => "field_template", :locals => { :form => field_form } | |
= link_to "Add new resource field", empty_field_resources_path, :remote => true | |
# controllers/resources_controller.rb | |
class ResourcesController < ApplicationController | |
def empty_field | |
respond_with do |format| | |
format.js | |
end | |
end | |
end | |
# empty_field.js.erb | |
<% | |
template = nil | |
form_for(Resource.new) do |f| | |
f.fields_for :fields, ResourceField.new, :child_index => Time.now.to_i do |form| | |
template = render :partial => "field_template", :locals => { :form => form } | |
end | |
end | |
%> | |
$("#resource_fields").append("<%= raw escape_javascript( template )%>"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment