<% @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?
# 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 %>
精彩评论