使用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> <%= extra_stop_form.text_field :elevator, :size => 1%></td>
<td> <%= extra_stop_form.text_field :action_type, :size => 5%></td>
<td> <%= extra_stop_form.select(:location_type, ([["pick-up"],["drop-off"],["extra_stop"]] )) %></td>
<td> <%= extra_stop_form.text_field :note, :size => 10%></td>
<td>^ / v</td>
<td> <%= link_to_function "Remove", "$(this).up('.jasf').remove()" %></td>
</tr>
<% end %>
</span>
错误:
未定义的局部变量或方法索引
不知道我做错了什么。
答案 0 :(得分:2)
您没有使用正确的语法将局部变量传递给partial,请在此处查看正确的语法http://api.rubyonrails.org/classes/ActionView/PartialRenderer.html