![]() |
Primary Key Writing
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::Basehere is the view code pretty understandable :
<form method="post" action="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 createhere is what i have now (after many changes and eventually working back to almost what i have above. :
def createwith 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:Symbol 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. |
I don't think you need the before_create and after_create functions.
I'd advise trying to assign the primary key manually: :
def create |
nope that doesn't work.
:
undefined method `vehicleID=' for #<Truck:0x36425c0>i tried something similar earlier but that didn't work either. |
Does anybody know how to do this? there HAS to be a way to do it its just freakin retarted if there isn't.
|
Have you tried asking on a RoR mailing list or forum?
|
Ya i got nothing not a single reply.
|
I think the problem is that its difficult to diagnose a problem in isolation. The reason your program isn't working may possibly not be directly related to the primary key. Is it possible to provide the source and SQL schema for the system?
|
Here are links for the shema download (mysql backup file) and the code ziped up
(note if your worried about viruses googlepages scans the files for them) http://sirbob1701.googlepages.com/VehicleLog.zip http://sirbob1701.googlepages.com/ba...0606141204.sql I should also note in the schema that if you change the trucks tables primary key non of the finds work. |
I'll take a look in around an hour or two when I get home.
|
I found a solution. It makes a strange sort of sense:
:
def createAs 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' |
| All times are GMT -5. The time now is 8:05 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC