Polymorphic help

With the help of some devs. I was able to list down commends of a
specific deal using the “def comments” method in the deal model
class.

However, what I also need is to display the owner/user who made the
comment via the @deal.comments loop. For example, something like this
would be ideal:

<% @deal.comments.each do |comment| %>
<%=h comment.comment %>
<%=h comment.user.first_name %>
<% end %>

Here is my actual code so far. I believe the key is to edit the “def
comments” method in the deal model class to include the user model or
something like that. Any help is appreciated…


deal show view

<% @deal.comments.each do |comment| %>







<% end %>

Comments
<%=h comment.comment %> <%= link_to ‘Show’, comment %> <%= link_to ‘Edit’, edit_comment_path(comment) %> <%= link_to ‘Destroy’, comment, :confirm => ‘Are you
sure?’, :method => :delete %>

model deal class

class Deal < ActiveRecord::Base
validates_presence_of :city_id

validates_presence_of :title, :description, :price, :value, :discount,
:savings, :goal, :countdown, :purchased
validates_length_of :title, :minimum => 5

belongs_to :city
belongs_to :user

has_many :features, :dependent => :destroy
has_many :photos, :dependent => :destroy

has_many :socials

accepts_nested_attributes_for :features, :reject_if => lambda { |a|
a[:description].blank? }, :allow_destroy => true
accepts_nested_attributes_for :photos, :reject_if => lambda { |a|
a[:photo].blank? }, :allow_destroy => true

define_index do
indexes title, :sortable => true
indexes description

has created_at

end

Polymorphic :through

has_many :through - The other side of polymorphic :through associations

def comments
self.socials.collect { |social|
social.entity if social.entity_type == “Comment”
}
end
end


social class model

class Social < ActiveRecord::Base
belongs_to :deal
belongs_to :user
belongs_to :entity, :polymorphic => true
has_many :comments

end