# Newbie RoR question

**URL:** <https://www.ruby-forum.com/t/newbie-ror-question/98831>\
**Category:** Rails\
**Created:** [July 18, 2006, 3:01pm UTC](https://www.ruby-forum.com/t/newbie-ror-question/98831 "2006-07-18T15:01:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elitegoodguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a9adbd/32.png) [@elitegoodguy](https://www.ruby-forum.com/u/elitegoodguy)\
**Post date:** [July 18, 2006, 3:01pm UTC](https://www.ruby-forum.com/t/newbie-ror-question/98831/1 "2006-07-18T15:01:05Z")

</div>

I am currently working on a small database project to track company  
assets. Right now my Database consists of 3 tables. 1 for the  
equipment, 1 for the users info, and 1 for the type of equipment.

I have all 3 databases working on a model test site using RoR. Where i  
am having trouble is getting the databases to talk together. I can’t  
find this answer anywhere else.

My main table is going to be the equipment table. I will enter in the  
different types of equipment and users in another table manually. I  
want to enter the information in the equipment table, while having drop  
down fields to the different users that might be associated with a  
particular asset and a drop down for the type of asset it is.

I can upload screenshots of my sample application if needed.

I’m hoping I’m making sense.

Eventually I want to click on the show view for a user and it will show  
all the equipment that the user has assigned to them. I’m just going 1  
step at a time right now.

Thanks for any help on this matter

---

<div class="post-metadata">

**Author:** ![elitegoodguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a9adbd/32.png) [@elitegoodguy](https://www.ruby-forum.com/u/elitegoodguy)\
**Post date:** [July 18, 2006, 3:05pm UTC](https://www.ruby-forum.com/t/newbie-ror-question/98831/2 "2006-07-18T15:05:42Z")

</div>

Elitegoodguy,

You need first to define what kind of associations u want between  
equipement, users, and equipement types.

Please tell us more, and I will help u.

Jean-Etienne

---

<div class="post-metadata">

**Author:** ![elitegoodguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a9adbd/32.png) [@elitegoodguy](https://www.ruby-forum.com/u/elitegoodguy)\
**Post date:** [July 18, 2006, 3:06pm UTC](https://www.ruby-forum.com/t/newbie-ror-question/98831/3 "2006-07-18T15:06:20Z")

</div>

You have to explain what you mean by “getting to talk to each other”  
and what actual problem or error you’re having when you try to  
accomplish your final goal.

If you think it will help, go ahead and take the screenshot and I’ll  
give it a shot.

- Rick

On 7/18/06, elitegoodguy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> want to enter the information in the equipment table, while having drop
> 
> Thanks for any help on this matter
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Rick Martinez  
Director of Technology  
Complexity Gaming

---

<div class="post-metadata">

**Author:** ![elitegoodguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a9adbd/32.png) [@elitegoodguy](https://www.ruby-forum.com/u/elitegoodguy)\
**Post date:** [July 18, 2006, 4:21pm UTC](https://www.ruby-forum.com/t/newbie-ror-question/98831/4 "2006-07-18T16:21:12Z")

</div>

Hi,

if i got this correctly, the main idea is:

jon, jane and juki, bob are users.  
axe, knife, underpants, shirt and chair are assets/equipment.  
weapons, clothes, and carpentry are types.

you want:

jon =\> axe, shirt, and chair (so basicly he has objects from the types  
of weapons, and clothes, and carpentry)

jane =\> axe (only weapons)

juki =\> underpants, shirt and chair(carpentry, and weapons)

bob =\> axe and knife(only weapons)

The relashinships you’ll need are:

MODELS:

class User  
has\_many :equipments #plural  
end

class Equipment  
belongs\_to :user #singular  
belongs\_to :type  
end

class Type(although i would be careful about the conventional word  
“type”)  
has\_many :equipments  
end

TABLES:

in the tables you define, you will need to add foreign keys  
(equipment\_id, type\_id, user\_id) according to the tables in the given  
relashinship.

and then, in the view, to access the given objects you want, you can do  
this inthe controller:

## @user = User.find(bob) or @type = Type.find(weapons)

## equipments\_for\_bob = @user.equipments or equipments\_for\_weapons = @type.equipments

if there are any more questions, or i totaly misunderstood you, be free  
to shoot em on.  
hope this helps,

shai

---

<div class="post-metadata">

**Author:** ![elitegoodguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a9adbd/32.png) [@elitegoodguy](https://www.ruby-forum.com/u/elitegoodguy)\
**Post date:** [July 18, 2006, 8:07pm UTC](https://www.ruby-forum.com/t/newbie-ror-question/98831/5 "2006-07-18T20:07:04Z")

</div>

Shai Hit it dead on…

Here’s my tables and fields

Equipment:  
equipment\_id  
UPC  
Type  
Make  
Model  
ServiceTag  
ExpressCode  
License  
LicenseKey  
ServiceDate  
Comments  
User

Types:  
type\_id  
Name  
Description

Users:  
user\_id  
FullName  
FirstName  
LastName  
Address  
City  
State  
Zip  
Phone

The users and types I’ll enter that information in first. Then goto the  
equipment/new page and enter

UPC  
Type {Choosing between all the different types I had entered in  
previously}  
Make  
Model  
ServiceTag  
ExpressCode  
License  
LicenseKey  
ServiceDate  
Comments  
User {Choosing between the users I had entered in previously}

Both User and Type as a drop down (I think Rails does this automatically  
if I do it right)

I think Shai had it right, but I tried as Shai suggested and broke  
things hence no screenshot. Even tried starting from scratch and same  
results. I’m sure it’ll just take alittle more time to get to know all  
the Rails quirks.

I’m going to try it again except without the views and layouts that I  
made.

Thanks soo much for all your help so far. I didn’t know that I would  
get soo many replies so fast.

---

<div class="post-metadata">

**Author:** ![elitegoodguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a9adbd/32.png) [@elitegoodguy](https://www.ruby-forum.com/u/elitegoodguy)\
**Post date:** [July 19, 2006, 1:14pm UTC](https://www.ruby-forum.com/t/newbie-ror-question/98831/6 "2006-07-19T13:14:57Z")

</div>

elitegoodguy wrote:

> Shai Hit it dead on…
> 
> Here’s my tables and fields
> 
> Equipment:  
> equipment\_id  
> UPC  
> Type  
> Make  
> Model  
> ServiceTag  
> ExpressCode  
> License  
> LicenseKey  
> ServiceDate  
> Comments  
> User
> 
> Types:  
> type\_id  
> Name  
> Description
> 
> Users:  
> user\_id  
> FullName  
> FirstName  
> LastName  
> Address  
> City  
> State  
> Zip  
> Phone

not that i know how the views are implemented, and if problems arised  
there, but either way, the tables and id’s aren’t quite correct; the  
user\_id, type\_id, and  
equipment\_id are all foreign keys, not the primary keys of the table.  
for example, the types table should be:

Types:  
id  
equipment\_id # foreign key  
name  
description

without the foreign key defined, the belongs\_to/has\_many won’t really do  
anything. before you implement the views, maybe you should check out ‘4  
days on rails’ a general great reference to learn from.

anyway, good luck with the project!  
later,

s
