Forum: Ruby on Rails NoMethodError when saving checked data in checkbox

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
new rails user (Guest)
on 2007-02-22 05:46
Another question from me, a new person to ROR.

table a (has column id and name) and table b (has column id and name),
they have many_many relationship. so, joint table a_b introduced. a_b
only has a_id and b_id.

I am using

<% for b in @bs %>
  <%= check_box("b",, ( ?
{:checked => 'checked'} : {:checked => false} )) %> <%= %>
<% end %>

to show all available b for a. it works.

I am using

  def update
    @a = A.find(params[:id])

    b = B.find(params["b"].to_i)
    unless << b

    if @a.update_attributes(params[:a])
      flash[:notice] = 'A was successfully updated.'
      redirect_to :action => 'show', :id => @a
      render :action => 'edit'

to save all info into table a and joint table a_b

however, I got the following error message:

 NoMethodError in AController#update

undefined method `to_i' for {"1"=>"1", "2"=>"0", "3"=>"0",

Any idea how to fix it? thanks.
This topic is locked and can not be replied to.