We help IT Professionals succeed at work.

Ruby On Rails - Foreign Key Lookup

cmgtech
cmgtech asked
on
4,653 Views
Last Modified: 2012-08-13
I have a one-to-many relationship between a 'file' and a 'directory'.  What I'd like is that in the 'file' scaffolding (maybe view is more appropriate?), a dropdown with all 'directory' listings.  I'm having a many-to-many issue, but I'm hoping that once I figure out one-to-many, I should be able to figure out many-to-many.

The best I can find on the internet show that I put a belongs_to in file model and a has_many in directory model.  How do I take it to the final step and create a dropdown that will allow me to assign directories to files?  

I assume that I modify the 'new' method in the file controller, but I'm having a hard time with syntax.  After modifying the controller, do I have to do anything to the view?

Any help is appreciated, or a website that outlines how to do this.  I have looked around on the web and can;t find anything that spells this out for me.  I'm not much of a programmer so I might not be assuming enough.

Thanks,

Mark

Comment
Watch Question

Information Architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
perfect.  you should start a blog of concise solutions to problems.

Author

Commented:
oh, and thanks so much.
Gertone (Geert Bormans)Information Architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
welcome
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.