Last active
September 9, 2016 19:41
-
-
Save danielolivaresd/f708a1a6d671aac0c1ab8ca9469b5053 to your computer and use it in GitHub Desktop.
Rails i18n for accepts_nested_attributes_for (with has_many) using anchors
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
# Singular. This works for the following | |
# form_for @tree do |f| | |
# We can use an anchor (&tree) to have the values available | |
tree: &tree | |
name: Nombre | |
age: Edad | |
# Plural. This works for the following | |
# # forest.rb | |
# class Forest < ApplicationRecord | |
# has_many :trees | |
# accepts_nested_attributes_for :trees, reject_if: :all_blank | |
# end | |
# | |
# # tree.rb | |
# class Tree < ApplicationRecord | |
# belongs_to :forest | |
# end | |
# | |
# # form.html.haml | |
# form_for @forest do |f| | |
# f.fields_for :trees do |trees_form| | |
trees: *tree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment