在哪里定义了model_form_counter(Rails 2?)

时间:2014-02-25 19:17:56

标签: ruby-on-rails forms counter

我有以下部分 _address_form.html.erb ,其中var address_form_counter 似乎是突然定义的(这是一个rails 2 app我'升级)。在rails 4版本中,此var未定义。

我无法分辨它的定义,并且需要以某种方式模仿rails 4中的这种行为。任何想法?

<%- 
  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 -%>

0 个答案:

没有答案