administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Documentation suggestion for nested forms - HasOne

Open danielsousaio opened this issue 6 years ago • 2 comments

It would be useful to explain that in order to have a has_one association in a form, one has to add

  has_one :thing
  accepts_nested_attributes_for :thing

to the parent model. Saying this because the Field::HasOne already supports nested form and allows the params.

https://github.com/thoughtbot/administrate/blob/3366bd10a4afaf5bc0c63ea0f5ecc12b5d1bae31/lib/administrate/field/has_one.rb#L8

danielsousaio avatar Oct 25 '17 01:10 danielsousaio

When you describe the two lines to be added:

has_one :thing
accepts_nested_attributes_for :thing

Do you think the first line can be assumed? And the second only if you'd want to modify (and not just display) the item?

Is there somewhere in our documentation that you think we'd be able to expand on to help make this clearer? If there is, do you think you'd be able to open a PR for that?

nickcharlton avatar Oct 29 '17 16:10 nickcharlton

As a side-note, HasMany is also supported with the administrate-field-nested_has_many plugin. There is also a caveat with model associations which are namespaced, but it can be workarounded as detailed here: https://github.com/nickcharlton/administrate-field-nested_has_many/issues/1#issuecomment-545394284

sedubois avatar Oct 23 '19 11:10 sedubois