This is my form:
<table>
<tbody>
<% form_for :HhActiveCarrier, @carriers, :url => { :action => "update" } do |f| %>
<% for carrier in @carriers %>
<tr>
<%= render :partial => "summary_detail", :locals => {:carrier => carrier, :f => f} %>
</tr>
<% end %>
</tbody>
</table>
<%= submit_tag "Update" %>
<% end %>
With my partial:
<td class="tn"><%= h(carrier.name.to_s()) -%></td>
<td class="sc"><%= h(carrier.country.to_s()) -%></td>
<td class="sc"><%= select_tag(:country, options_for_select(@countries)) -%></td>
This is the controller where I define the variables:
class ActiveCarriersController < ApplicationController
def index
@carriers = HhActiveCarrier.find(:all)
for carrier in @carriers
country = carrier["country"]
if country.nil?
carrier["country"] = "none"
end
end
@countries = ["USA", "UK", "Canada"]
end
All of this works. However, if I make a change to the drop down list in the form to this:
<td class="sc"><%= f.select("country", @countries) -%></td>
I get this error:
Showing app/views/active_carriers/_summary_detail.rhtml where line #3 raised:
undefined method `country' for #<Array:0xef79a08>
Extracted source (around line #3):
1: <td class="tn"><%= h(carrier.name.to_s()) -%></td>
2: <td class="sc"><%= h(carrier.country.to_s()) -%></td>
3: <td class="sc"><%= f.select("country", @countries) -%></td>
Trace of template inclusion: /app/views/active_carriers/_summary.rhtml, >/app/views/active_carriers/index.rhtml
What am I doing wrong with my form select? I am using Ruby on Rails 2.3.8
Stackoverflow is telling me that I don't have much explanation for all the code i have, so I am just writing stuff. I don't really know what else to explain, so ask questions if you don't understand everything. Also I couldn't quote the error message because Stackoverflow kept telling me I had code that didn't have the code blocks, so I had to put code blocks around the error message.