more models merged to one event variable
when during a bigger site, i wan't to make a dashboard, and on the dashborad i want some kind of "events" or "activity".. so i'd figured this out
# Controller
replies = current_user.replies.order('updated_at desc')
topics = current_user.topics.order('updated_at desc')
@events = (replies + topics)
# View
- for event in @events
开发者_如何学运维 %div.forum-row
%div.date
= link_to "Link", event
= time_ago_in_words(event.updated_at)
=t :home_ago
%div.by
= t(:home_by, :href => link_to(event.user.username, "#")).html_safe
%div.clear
= " ".html_safe
%div.clear
And that's work fantastic, but i want to at first make a bold line where it says what type it is.. like
"Posted a Topic: You posted a Topic 4 minutes ago"
or something like that.. But i can't see how to do that when i'm merging them together in the on @events..
You can use the object class name to output the type of event:
"Posted a #{event.class.name}: You posted a #{event.class.name} 4 minutes ago"
精彩评论