-
-
Save mirrec/1852006 to your computer and use it in GitHub Desktop.
nested form in simple_form
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
# 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