How to refence to other table items

Hi

Since I am noob with ruby still I have question. This is my setup.

2 tables and their fields.

Users table

login
imitem_id

Imitems table

id
groupname

Now all users have several Imitems and those are saved on user table
with imitem_id which points back to
id on Imitems table.

Now on Imitem controller I have action:

def welcome

loginname = request.env[‘REMOTE_USER’]

@users = User.find(:all, :conditions => [ “login = ?”, loginname])

end

ie. it finds all users who’s loginname is the same as their
REMOTE_USER name

and on welcome.html.erb page it will print out all those entries which
match that sql query.

<% form_for :user, @user, :url => { :action => “select” }, :html =>
{:id => ‘g
rpform’, :name => ‘grpform’, :target => ‘_parent’, :onsubmit =>
‘return validate_task(this);’ } do |f| %>
<% for user in @users %>

<%= h(user.imitem_id) %> < %= link_t o 'Destroy', user, :confirm => 'Are you sure you want to cancel this group sub scription ?', :method => :delete %> [Edit] [MDM disable]

<% end %>
<% end %>

Now however I need to print out also respective group name from Imitem
table where loop

<% for user in @users %>

loops thru user items and then it should find out match for the items
where

user.imitem_id == imitem.id (and then return imitem.groupname)

ie. when user imitem.id number is equal to the imitem.id then I should
find out what is that groupname on
imitem table ?

Any ideas ?

first of all, there is no request.env[‘REMOTE_USER’]. it just does not
work that way. Have a look at acts_as_authenticated and install and use
that.

Well there is and it works fine. But thats not the thing what I am
asking here. You can think that loginname =
request.env[‘REMOTE_USER’]
could be anything like loginname=jane

and I figured it out

<% @imitems.each do |imitem| %>
<% if imitem.id == user.imitem_id %>
<%= imitem.grpname %>
<% end %>
<% end %>

also needed to add on models

user.rb

has_many :imitems

imitem.rb

belongs_to :user

I didn’t believe that and I even tested it myself. I put:

“puts request.env[‘REMOTE_USER’]” in my blogs_controller index action
and
checked it in Firefox on Windows XP

It returned nil.

I checked it on IE7 on WindowsXP

It returned nil.

I checked it on Firefox in Ubuntu.

It returned nil.