Skip to content

Instantly share code, notes, and snippets.

@mirrec
Created February 17, 2012 08:58
Show Gist options
  • Save mirrec/1852006 to your computer and use it in GitHub Desktop.
Save mirrec/1852006 to your computer and use it in GitHub Desktop.
nested form in simple_form
# app/models/building.rb
class Building < ActiveRecord::Base
has_many :people, :dependent => :destroy
accepts_nested_attributes_for :people, :allow_destroy => true
end
# app/views/buildings/_form.html.erb
<%= simple_form_for(@building) do |f| %>
<%= f.input :name %>
<%= f.simple_fields_for :people do |builder| %>
<%= render 'person_fields', :f => builder %>
<% end %>
<%= f.submit %>
<% end %>
# app/views/buildings/_person_fields.html.erb
<%= f.input :firstname, :label => t("simple_form.labels.person.firstname") %>
<%= f.input :surname, :label => t("simple_form.labels.person.surname") %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment