使用Ruby 1.8.6 & Rails 1.2。Ruby on Rails:從單個視圖/控制器更新多個模型
型號:Job
,JobExtraStop
:從View
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>
錯誤:
Undefined Local Variable or method index
不知道我在做什麼錯。
這將是值得你的努力,以更新到Rails 3 –
謝謝!它在這個特定時刻不是一個選項。 – sunny31