# Getting Foreign Key to work!

**URL:** <https://www.ruby-forum.com/t/getting-foreign-key-to-work/143960>\
**Category:** Rails\
**Created:** [July 24, 2008, 7:18am UTC](https://www.ruby-forum.com/t/getting-foreign-key-to-work/143960 "2008-07-24T07:18:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![curtdbz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47c2d/32.png) [@curtdbz](https://www.ruby-forum.com/u/curtdbz)\
**Post date:** [July 24, 2008, 7:18am UTC](https://www.ruby-forum.com/t/getting-foreign-key-to-work/143960/1 "2008-07-24T07:18:02Z")

</div>

Okay. So I have this simple site, which includes Recipes and then  
Comments.

I want ppl to be able to comment on the recipes, and so I made comments  
have a recipe\_id as it’s foreign key etc. I’m not that much of a noob  
to not know that stuff.

When I click on a recipe, and then make a new comment and click ‘submit’  
(for the comment) it submits it, but it still has recipe\_id as nil! I  
know how to make the comment know that it’s for that particular recipe  
through the command line, i.e.:

c = Comment.find(1)  
r = Recipe.find(1)  
r.comments \<\< c  
r.save

But how do I make my site do that automatically when I click the submit  
button? I’ve been trying for DAYS… Please help me.! Thank you so  
much.
