Hello, I am having trouble getting the UPDATE and CREATE functions to work with a table that has a child relationship to a parent table. The model for the Task table has a child relationship to the table Project. This is stipulated in models/task.rb with: belongs_to :project The model for the Project table has a parent relationship to the table Task. This is stipulated in models/project.rb with: has_many :tasks But when I attempt to update or create a new task, I get this error: undefined method ` project_id='' for #<Task:0x25594cc> The error page points to controllers/task_controller.rb as the source of the error, but the MySQL request that it displays includes a value for project_id. What is wrong here? In the tutorials I have seen, they all indicate that by stipulating the parent-child relationship in the model files, the update and create statements will simply know what to do. What am I missing? Thanks in advance, Nathan -- Nathan Mealey Website Manager & Administrative Director Cycle-Smart, Inc. P.O. Box 1482 Northampton, MA 01061-1482 nathan-mPKOtHdLgT0QaXB9iyTzyw@public.gmane.org (413) 210-7984 (512) 681-7043 Fax _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 9/3/05, Nathan Mealey <nathan-mPKOtHdLgT0QaXB9iyTzyw@public.gmane.org> wrote:> > Hello, > I am having trouble getting the UPDATE and CREATE functions to work with a > table that has a child relationship to a parent table. > > The model for the Task table has a child relationship to the table > Project. This is stipulated in models/task.rb with: belongs_to :project > > The model for the Project table has a parent relationship to the table > Task. This is stipulated in models/project.rb with: has_many :tasks > > But when I attempt to update or create a new task, I get this error: undefined > method ` project_id='' for #<Task:0x25594cc> > > > The error page points to controllers/task_controller.rb as the source of > the error, but the MySQL request that it displays includes a value for > project_id. > > > What is wrong here? In the tutorials I have seen, they all indicate that > by stipulating the parent-child relationship in the model files, the update > and create statements will simply know what to do. > > > What am I missing? >Looks like a syntax error in your code. Did you notice the equal''s sign after project_id in your error message? That probably means ruby is trying to interpret ''project_id='' as an object, which is probably due to a simple syntax error somewhere. Chris _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails