Reputation: 5005
<% @contacts.each do |contact| %>
<%= contact.company_id %>
<% end %>
I want to get the company_id's name somehow from the other table.
I've tried <%= contact.company_id.collect(&:name) %>
without success can i get some help here?
Upvotes: 0
Views: 2864
Reputation: 83680
# Models
class Contact < ActiveRecord::Base
belongs_to :company
end
class Company < ActiveRecord::Base
has_many :contacts
end
<% @contacts.each do |contact| %>
<%= contact.company.name %>
<% end %>
Upvotes: 7