Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relationship Issues

 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got two tables, Users and Statuses. I want the user_id index from Statuses to be the id from Users. Right now, I can create a new user from a form and all records are created correctly. When I try to create a new status for that user in the new status form, by putting the id number in the user_id field, and some inane comment in the content field, only the id and content records are created for Status, and user_id is nil. I can't figure out why! Here are the rb files for each:







Can somebody tell me what I've done wrong? I've been staring at this for so long it is starting to make no sense.
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I figured out a way to update Status from the console. When I use update_attribute to set the user_id property in Status, the web pages function properly. When I created another user and made another status for them again the user_id property was nil. I can fix it from the console, but I need to figure out what is going on here. My problem then, is why is user_id not being assigned the value of id from the User table. There must be something wrong with the way Statuses are being put into the database if the associations work once the missing property is set. Where should I begin to troubleshoot?
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the problem. When Status was first migrated, it had a name property that was later changed to user_id. I forgot to update the controller to reflect that change in the permitted parameters. Now it works! See, I knew posting here was a good idea!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic