On 26 September 2011 14:40, Di Zou <[email protected]> wrote:
> I am using Rails 2.3.8. I have a view with a list of mobile carriers. I
> want to assign a country to each mobile carrier. I do this by having a
> drop down list with available countries for the user to select.
>
> This is my form:
>
> <table>
>  <tbody>
>  <% form_for :HhActiveCarrier, @carriers, :url => { :action => "update"

It is not legal html to have a form inside a table, unless it is
entirely within one cell of the table.  You may put the complete table
inside the form.

> } 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
>  carrier = HhActiveCarrier.find(params[:name])
>
>        redirect_to( :action => "index" )
>    end
>
>
> When I click the "Update" button, I want to have the "country" of each
> HHActiveCarrier to be set. Right now this is the error I get:
>
> Couldn't find HhActiveCarrier without an ID

That means that you have attempted a find on that table without
specifying an id.  Look at the line of code the error points to to
find out why.  You can look in log/development.log to see what params
are being passed.  If you still cannot see it the have a look at the
Rails Guide on debugging, in particular you could use ruby-debug to
break into your code and inspect the data and follow the flow.

Colin

-- 
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