Habtm only saving one record

I use habtm and a mulitline select to select which publications a
journalist works on.

class Journalist < ActiveRecord::Base
has_and_belongs_to_many :publications


class Publication < ActiveRecord::Base
has_and_belongs_to_many :journalists

When I make changes in the select, only the first selected item gets a
record in the habtm table:

From the log:
Parameters: {“commit”=>“Update Journalist”,
“journalist”=>{“publication_ids”=>[“3,5,4,1”], },
“utf8”=>“✓”, “id”=>“7”}

Then some rows down(!?):
INSERT INTO “journalists_publications” (“publication_id”,
“journalist_id”) VALUES (3, 7)

So, what happened to (5,7), (4,7) and (1,7)???

def self.up
create_table :journalists_publications, :id => false do |t|
t.references :journalist, :publication
add_index :journalists_publications, :journalist_id
add_index :journalists_publications, :publication_id

<%= form_for(@publication, :remote => true) do |f| %>
<%= f.collection_select(:journalist_ids,
Journalist.limit(20).order(‘id’), :id, :name, {}, {:multiple => true})
<% end %>

@journalist = Journalist.find(params[:id])
if @journalist.update_attributes(params[:journalist])

Does anyone have a clue?
Rails 3.0.5

This gets even stranger.

The problem is that the parameter from the mulitline collection_select
is an array with ONE element! The element is a string “3,5,4,1”. To
update the habtm I need an array of four integer elements [3,5,4,1]

How can this happen???

:frowning: jeb

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs