Forum: Ruby on Rails Newbie Question. I'm dumb with forms and foreign keys

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dave K. (Guest)
on 2006-01-09 05:04
For some reason I am just not able to get this.

I am trying to setup an organizational hierarchy, so I have a
organization which works fine.  From there I want to be able to define
new divisions, departments, areas, etc.

For creating a Division, my original thought was to pass the
organization's id to the new organization unit form, and then do a => params[:id]) but of course that fails
because it looks like doing a ignores any id or foreign keys
in the object.

I am assuming (and hoping) there is a simple solution or convention on
how to accomplish this and I'm just completely missing it.

Pat M. (Guest)
on 2006-01-09 05:56
(Received via mailing list)
d =
d.organization_id = params[:id]

One question I have for others, is there any reason or advantage to
use objects instead of purely the fkey?  i.e.
d.organization = Organization.find(params[:id])

One simple reason is that you have fewer database issues.  If you were
to change the fkey name, you simply need to update it in the model.
That's unlikely though, and I was wondering if there are any practical
reasons why you might want to access it via association, which has the
overhead of pulling the record from the db.

This topic is locked and can not be replied to.