Newbie RoR question

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

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

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 [email protected] 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/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rick Martinez
Director of Technology
Complexity Gaming

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

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.

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