-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
_form.html.erb
38 lines (29 loc) · 1.25 KB
/
_form.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<%#
# 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 |title, attributes| -%>
<fieldset class="<%= "field-unit--nested" if title.present? %>">
<% if title.present? %>
<legend><%= t "helpers.label.#{f.object_name}.#{title}", default: title %></legend>
<% end %>
<% attributes.each do |attribute| %>
<div class="field-unit field-unit--<%= attribute.html_class %>">
<%= render_field attribute, f: has_one_f %>
</div>
<% end %>
</fieldset>
<% end -%>
</fieldset>
<% end %>