I found a solution. It makes a strange sort of sense:
def create
@a_truck = Truck.new(@params['truck'])
@a_truck.id = @params['truck']['vehicleID']
if @a_truck.save
redirect_to :action => 'list'
else
render_action 'new'
end
end The "id" attribute doesn't appear to change if you alter the primary key, which I guess makes a bit of sense. As for setting it explicitly, I'd hazard a guess that's because the default activerecord constructor specifically avoids setting the primary key when given a hash. I guess that's to prevent accidental setting of the primary key when it's not intended. I can't say I approve...
As for your problem with linking the drivers table to the trucks table, you need a many-to-many relationship, which links two tables using an intermediate (ie. bridges). In Rails the function to do this is "has_and_belongs_to_many", which you should place in your truck.rb file:
has_and_belongs_to_many :drivers, :join_table => 'bridges', :foreign_key => 'driverssID', :association_foreign_key => 'vehicleID'
Edit: forgot the :drivers argument.