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(:carrier, "country", @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
def update
carriers = HhActiveCarrier.find(:all)
for carrier in carriers
carrier.update_attributes(params[:country])
end
redirect_to( :action => "index" )
end
What I want to happen is after I click the "Update" button, I want the new country selected from the drop down list to be put into the HHActiveCarrier model. With the code I have right now, I get this error:
OCIError: ORA-00904: "ID": invalid identifier: UPDATE hh_active_carriers SET name = 'AT&T', country = null WHERE id = null
How would I go about updating the attributes this? I am using ruby on rails 2.3.8.
Edit:
Added parameters hash from development log:
parameters: {"commit"=>"Update", "carrier"=>{"country"=>"USA"}, "action"=>"update", "controller"=>"active_carriers"}
content_type: #
accepts: [#, #, #]
raw_post: "carrier%5Bcountry%5D=USA&carrier%5Bcountry%5D=USA&carrier%5Bcountry%5D=USA&carrier%5Bcountry%5D=USA&commit=Update"
query_parameters: {}
request_parameters: {"commit"=>"Update", "action"=>"update", "carrier"=>{"country"=>"USA"}, "controller"=>"active_carriers"}
Edit3:
Form:
<table>
<tbody>
<% form_for :HhActiveCarrier, :url => { :action => "update" } do |f| %>
<% for carrier in @carriers %>
<tr>
<%= render :partial => "layouts/summary_detail", :locals => {:carrier => carrier, :f => f} %>
</tr>
<% end %>
</tbody>
</table>
<%= submit_tag "Update" %>
<% end %>
Partial:
<td class="tn"><%= h(carrier.name.to_s()) %></td>
<td class="sc"><%= h(carrier.id.to_s()) %></td>
<td class="sc"><%= h(carrier.country.to_s()) %></td>
<td class="sc"><%= f.collection_select :country, HhActiveCarrier::COUNTRIES, :to_s, :to_s %></td>
Controller:
class ActiveCarriersController < ApplicationController
def index
@carriers = HhActiveCarrier.find(:all)
for carrier in @carriers
country = carrier["country"]
if country.nil?
carrier["country"] = "none"
end
end
end
def update
#update code
redirect_to( :action => "index" )
end
end
=in<%= f.fields_for :carrier do |carrier_fields| %>to solve the first error aboutunexpected ')'=to the <% form_for ... %>` I can never remember which is correct, but I make that mistake all time.