Skip to content

Commit

Permalink
Add has-many form sample
Browse files Browse the repository at this point in the history
  • Loading branch information
javierjulio committed Nov 30, 2023
1 parent 22a2f4b commit f9bb078
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/admin/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
f.input :password, input_html: { autocomplete: "new-password" }
f.input :email
end
f.inputs "User Addresses" do
f.has_many :user_addresses, heading: false do |t|
t.input :fullname
t.input :address_line1
t.input :city
t.input :state
t.input :zipcode
t.input :country
end
end
f.actions
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class User < ApplicationRecord

has_many :user_addresses

accepts_nested_attributes_for :user_addresses, allow_destroy: true

attr_accessor :password
before_save :prepare_password

Expand Down

0 comments on commit f9bb078

Please sign in to comment.