Skip to content

Instantly share code, notes, and snippets.

@benlieb
Created February 21, 2014 19:43
Show Gist options
  • Save benlieb/9141933 to your computer and use it in GitHub Desktop.
Save benlieb/9141933 to your computer and use it in GitHub Desktop.
<%-
address = address_form
index = address_form_counter == 0 ? "INDEX" : address_form_counter
new_or_existing = address.new_record? ? 'new' : 'existing'
id_or_index = address.new_record? ? index : address.id
prefix = "#{parent}[#{new_or_existing}_address_attributes][]"
-%>
<div class="address">
<% fields_for prefix, address do |address_form| -%>
<p class="required">
<%- unless parent == "person" -%>
Description: <%= address_form.text_field :description, :index => id_or_index, :style => "width:18.5em;" %> <br />
<%- end -%>
<%= address_form.text_field :line1, :index => id_or_index, :style => "width:24.5em;" %> <br />
<%= address_form.text_field :line2, :index => id_or_index, :style => "width:24.5em;" %> <br />
<%= address_form.text_field :city, :index => id_or_index %>
<%= address_form.text_field :state, :index => id_or_index, :style => "width:2em;" %>
<%= address_form.text_field :zip, :index => id_or_index, :style => "width:9em;" %> <br/>
<%= address_form.country_select :country, ["United States", "Canada"], {}, :index => id_or_index %> <br/>
<%- unless parent == "person" -%>
<%= address_form.check_box :is_primary,
:index => id_or_index,
:class => "is_primary_address",
:onclick => "unsetOtherPrimaryAddressCheckboxes($(this))" %>
<%= address_form.label :is_primary, "This is the primary address",
:index => id_or_index,
:onclick => "unsetOtherPrimaryAddressCheckboxes($(this.getAttribute('for')))"
%> <br/>
<%= link_to_function("#{address.new_record? ? "Remove" : "Delete"} this address", "$(this).up('.address').remove()") %>
<%- end -%>
</p>
</div>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment