1

使用 Ruby 1.8.6 和 Rails 1.2。

型号:Job, JobExtraStop:

class JobExtraStop < ActiveRecord::Base  
  belongs_to :job 
end 

class Job < ActiveRecord::Base 
  belongs_to :lead, :foreign_key => :id 
  has_one :quote, :foreign_key => :id 
  has_many :credit_card 
  has_many :job_extra_stops 
end 

查看代码:

主视图

<%= render_partial 'jobs/job_address_stop_fields', "stop" => stop, "index"=> index %>   

部分称为:

 <span class="jasf" id="lead_form_adrr_fields">

 <% fields_for "job_extra_stop[#{index}]", stop do |extra_stop_form| %>
<tr>
         <td><%= extra_stop_form.text_field :st_num, :size => 2%></td>
          <td><%= extra_stop_form.text_field :st_name,  :size => 15%></td>
          <td><%= extra_stop_form.text_field :apt_num,  :size => 2%></td>
          <td><%= extra_stop_form.text_field :city,  :size => 9%></td>
          <td><%= extra_stop_form.text_field :zip,  :size => 5%></td>
          <td><%= extra_stop_form.select(:state,( [[ "Select State", "" ]] + State::NAMES)) %>

          </td>
          <td><%= extra_stop_form.text_field :floor,  :size => 2%></td>
          <td>&nbsp;&nbsp;<%= extra_stop_form.text_field :elevator, :size => 1%></td>
          <td>&nbsp;&nbsp;<%= extra_stop_form.text_field :action_type,  :size => 5%></td>
          <td>&nbsp;&nbsp;<%= extra_stop_form.select(:location_type, ([["pick-up"],["drop-off"],["extra_stop"]] )) %></td>
          <td>&nbsp;&nbsp;<%= extra_stop_form.text_field :note,  :size => 10%></td>
          <td>^ / v</td>
          <td>&nbsp;&nbsp;<%= link_to_function "Remove", "$(this).up('.jasf').remove()" %></td>
</tr> 
<% end %> 
</span> 

错误:

未定义的局部变量或方法索引

不知道我做错了什么。

4

1 回答 1

2

您没有使用正确的语法将局部变量传递给您的局部变量,请在此处检查正确的语法http://api.rubyonrails.org/classes/ActionView/PartialRenderer.html

于 2012-06-19T18:45:40.413 回答