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
<table>
<tr>
<th>Comments</th>
</tr>
<% @deal.comments.each do |comment| %>
<tr>
<td><%=h comment.comment %></td>
<td><%= link_to ''Show'', comment %></td>
<td><%= link_to ''Edit'',
edit_comment_path(comment) %></td>
<td><%= link_to ''Destroy'', comment, :confirm
=> ''Are you
sure?'', :method => :delete %></td>
</tr>
<% end %>
</table>
---------------
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
# http://blog.hasmanythrough.com/2006/4/3/polymorphic-through
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
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.