Non-autoincremented primary keys

Hi,

I am trying to populate a legacy table with a primary key of ‘id’, but
the id is not auto-incremented (the id is currently populated with the
results from another table that has an auto-incremented id).

I’m POSTing xml to a controller created by the scaffold_resource
generator
e.g.:

echo ’

2
Tom
’ | curl -X POST -H ‘Content-type: text/xml’ -d @-
http://localhost:3000/users

However, the id specified in the xml is not saved.

The development log shows the following parameters being received:

Parameters: {“user”=>{“name”=>“Dick”, “id”=>“2”}, “action”=>“create”,
“controller”=>“users”}

However, in users_controller.create, I am having to explicitly set the
id myself

@user = User.new(params[:user])
@user.id = params[:user][:id]

Is there a better way to do this? A setting perhaps regarding a non-
autoincremented primary key?

Thanks,
Shawn

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