I am trying to implement a simple activity stream.
Given that User abc creates a post 123 And User xyz comments on 123. Then user abc activity stream should look something like: <ul> <li>User <a href="/users/abc">abc</a> created a post <a href="/users/abc/posts/123">123</a></li> <li>User <a href="/users/xyz">xyz</a> commented on post <a href="/users/abc/posts/123">123</a></li> </ul>
I prefer to populate the action model (rather than multiple requests in the controller). I added the 'after_create' binding to the post and comment models to populate the activity:
class Post < ActiveRecord after_create do ActivityCreate(:user_id => self.user_id, :description => "created a post") end end
I was thinking about storing special fields that I need to create routes and links, such as post_id, etc., but I may have more actions that I want to track later, like, dislike, favorites, etc. , and I want a flexible way to create operation descriptions.
So my question is, what is an efficient way to put link_to in the operation description? Is there any c-type style printing method that will be evaluated later?
Example:
description = ["User? commented on the post?", user_path (User.find (self.user_id)), post_path (Post.find (self.id))]
And then evaluate it on the template side?
Homan source share