I'm writing an app where the primary key is not automaticlly incremented. It will be a value (checked) taken from the user and put into the table. Right now i cannot do that without unsetting the primary key which will then invalidate my search options. So you can see here is the controller code
class Truck < ActiveRecord::Base
set_primary_key :vehicleID
def before_create
self.id = vehicleID
end
def before_update
self.id = vehicleID
end
has_many :oils
has_many :tows
has_many :appearances
has_many :brakes
has_many :bridges
has_many :inspections
has_many :rdifferentials
has_many :repairs
has_many :treds
end
here is the view code pretty understandable
<form method="post" action="create">
<br>
<b>Vehicle Number:</b><br/>
<input id="truck_vehicleID" name="truck[vehicleID]" size="20" type="number" value=""/><br/>
<b>Vin:</b><br/>
<input id="truck_vin" name="truck[vin]" size="20" type="number" value=""/><br/>
<b>Current Mileage:</b><br/>
<input id="truck_curmileage" name="truck[curmileage]" size="20" type="number" value=""/><br/>
<b>Tag:</b><br/>
<input id="truck_plate" name="truck[plate]" size="20" type="text" value=""/><br/>
<b>Oil Change Interval:</b><br/>
<input id="truck_oilInt" name="truck[oilInt]" size="20" type="number" value=""/><br/>
</p>
<input type="submit" value="Create">
now it doesn't seem to be passing the vehicleID proplerly or something. I've tryed the controller many different ways and almost have it i think. here is it in its original that wasn't working but i think should definately worked
def create
@a_truck = Truck.new(@params['truck'])
if @a_truck.save
redirect_to :action => 'list'
else
render_action 'new'
end
here is what i have now (after many changes and eventually working back to almost what i have above.
def create
@a_truck = Truck.new(Truck.vehicleID = :truck.vehicleID, @params['truck'])
if @a_truck.save
redirect_to :action => 'list'
else
render_action 'new'
end
with the oringal i got the error message that in the table vehicleID is null and can't be with the new one i simple get that
undefined method `vehicleID' for :truck

ymbol
i really need hlep with this if you need more information you can ask here or check a previous thread i had with my db design and original implementations.