<%#
# HasOne Form Partial

This partial renders an input element for has_one relationships.

The form will be rendered as nested_from to parent relationship.

## Local variables:

- `f`:
  A Rails form generator, used to help create the appropriate input fields.
- `field`:
  An instance of [Administrate::Field::HasOne][1].
  A wrapper around the has_one relationship pulled from the database.

[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasOne
%>

<%= f.fields_for field.attribute, field.data || field.nested_form.resource.class.new do |has_one_f| %>
  <fieldset class="field-unit--nested">
    <legend><%= t "helpers.label.#{f.object_name}.#{field.nested_form.resource_name}", default: field.nested_form.resource_name.titleize %></legend>
    <% field.nested_form.attributes.each do |attribute| -%>
      <div class="field-unit field-unit--<%= attribute.html_class %>">
        <%= render_field attribute, f: has_one_f %>
      </div>
    <% end -%>
  </fieldset>
<% end %>

<%#
# HasOne Form Partial

This partial renders an input element for has_one relationships.

The form will be rendered as nested_from to parent relationship.

## Local variables:

- `f`:
  A Rails form generator, used to help create the appropriate input fields.
- `field`:
  An instance of [Administrate::Field::HasOne][1].
  A wrapper around the has_one relationship pulled from the database.

[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasOne
%>

<%= f.fields_for field.attribute, field.data || field.nested_form.resource.class.new do |has_one_f| %>
  <fieldset class="field-unit--nested">
    <legend><%= t "helpers.label.#{f.object_name}.#{field.name}", default: field.name.titleize %></legend>
    <% field.nested_form.attributes.each do |attribute| -%>
      <div class="field-unit field-unit--<%= attribute.html_class %>">
        <%= render_field attribute, f: has_one_f %>
      </div>
    <% end -%>
  </fieldset>
<% end %>

Use field.name rather than resource_name for has_one relationships
Use field.name rather than resource_name for has_one relationships

If a model has multiple has_one relationships to the same model (e.g. two polymorphic associations with different scopes), we can't override the field label for the two associations, we can only change the translation for both at the same time, as the translation is based on the associated class name, not the association name.

This change uses the association name as the lookup field and default value for the label for has_one relationships, allowing multiple relations to the same class to have their own translated labels.
