I'm also a newbie. Here's how I do it:
There is a technique called habtm -- has and belongs to many.
I am not going to show you habtm, because I don't use it. Habtm
describes the trivial situation where the pivot table contains only
ids from the two tables it joins. You may find you want other data in
your join table besides just those two ids, and thus you would use the
method I am describing. It is in the section in Agile Rails
Development called "Using Models as Join Tables".
You make what's called a "pivot table", or an "intermediate join
table". It is a table that sits between your two tables. At the very
least, it has an id from each table. Your model would be called
your table would be called
and it would consist of
but could have other columns as well.
Then, in your user_file model, you have these lines:
(notice the pluralization -- when you talk about a model on the "one"
side of a one-to-many relationship, it's singular - -on the many side,
in your user model, you have these lines
has_many :files, :through => :user_files
and your user table must have, at the very least, these columns:
then of course in your file model, you have
has_many :users, :through => :user_files
and your file model must have, at the very least, these columns
And rails style says that all these id columns should be integers, but
if you want to fight that, there are ways.
That's it, good luck.