NoMethodError when saving checked data in checkbox

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.