So what I have is a table called HHActiveCarrier with three columns, an
"Name", "ID", and "Country". Each row in the table is a carrier. I'm
trying to make something that lets you update the country of each
carrier all at once. I went back in my code and changed a bunch of
stuff.

My controller is still generally the same. I'm going to leave the code
in ActiveCarrierController.index the same for now.

Here is what I have now:

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

        redirect_to( :action => "index" )
    end
end

This is what my form looks like now:

<table>
  <thead>
    <tr>
      <th><%= "Active Carrier" %></th>
      <th><%= "" %></th>
      <th><%= "Country" %></th>
    </tr>
  </thead>
  <tbody>
  <%= form_tag :action => 'update', :id => params[:id] %>
    <% for @carrier in @carriers %>
      <% fields_for "carrier[]" do |f| %>
        <tr>
          <td class="tn"><%= f.text_field :name, :readonly => true
%></td>
          <td class="tn"><%= f.hidden_field :id %></td>
          <td class="tn"><%= f.select :country, @countries %></td>
        </tr>
      <% end %>
    <% end %>
  </tbody>
</table>
  <%= submit_tag 'Update' %>
  <%= end_form_tag %>

If I make a selection in the drop down list and I click "Update", this 
is what my request_parameters look like:

request_parameters: {"commit"=>"Update",
 "action"=>"update",
 "carrier"=>
  {"6"=>{"name"=>"Sprint Nextel", "country"=>"USA", "id"=>"6"},
   "7"=>{"name"=>"Verizon", "country"=>"USA", "id"=>"7"},
   "2"=>{"name"=>"T-Mobile US", "country"=>"UK", "id"=>"2"},
   "4"=>{"name"=>"AT&T", "country"=>"USA", "id"=>"4"},
   "5"=>{"name"=>"Sprint Nextel", "country"=>"USA", "id"=>"5"}},
 "controller"=>"active_carriers"}

How do I take the data in the request_parameters and update each row in
my database? Thanks.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to