i have a (hopefully) simple question that might have been answered before.. i just couldnt find it... well, here we go, should be easy enough.
I have this schema
create_table "items", :force => true do |t|
create_table "users", :force => true do |t|
And I have this in my form for adding a new item:
<%= collection_select(:item, :user_id, User.all, :id, :name) %>
Now, it works, data is saved correctly (I already set up the proper correlations). What i want though, is to display in the items index, the name of the person the item is assigned to, instead of just an ID number.
In items/index I have:
<td><%= item.user_id. %></td>
but i rather want something like
only, it won't work - I guess I need some action in my controller.
Can you help me please? :)
EDIT here is some more details:
class User < ActiveRecord::Base
class Item < ActiveRecord::Base
Add this to your Items class:
class Items < ActiveRecord::Base belongs_to :user end
item.user.name should work.