:has_many and :belongs_to: how do they work

I am new to rails, and don't know how :has many and :belongs to work, but I really like the idea of being able to say, for example email.accounts, and I was wonderign what the requirements are. Does this system work off of foreign keys, or does it work off of a system like this for example email table ___________ email account

Accounts table ______________ name email

meaning, that it matches the two email fieldnames?

By default, ActiveRecord expects foreign keys to be named <table>_id. In your example, account would have a field called email_id of type :integer. You can then use belongs_to and has_many.

I would also suggest you spend some time trawling the web for tutorials/books. There are many out there and they'll help you understand how Rails is put together.

Max

Ben, I highly suggest you get the book Agile Development on Rails, and read it. It will give you a good understanding of how Rails works. Without a good understanding of the underlying technology, you’ll probably keep running into walls when coding. But once you understanding it, coding becomes fairly simple.