# Activity Log - messages with links - Strategy?

**URL:** <https://www.ruby-forum.com/t/activity-log-messages-with-links-strategy/173121>\
**Category:** Rails\
**Created:** [August 3, 2009, 1:58pm UTC](https://www.ruby-forum.com/t/activity-log-messages-with-links-strategy/173121 "2009-08-03T13:58:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 3, 2009, 1:58pm UTC](https://www.ruby-forum.com/t/activity-log-messages-with-links-strategy/173121/1 "2009-08-03T13:58:03Z")

</div>

Hi all,

Im looking to write an activity log as part of the dashboard for one  
of my apps. The log should show messages like

“Vinay created the project Acme Inc Website”, “You completed 2 tasks  
in the project Acme Inc website”

and so on.

So i went about creating an activities table with controller, action,  
user, message and timestamps. Now the messages the user sees in his  
dashboard should have links on words like “You”, “Vinay”, “Acme Inc  
Website” and so on such that they link to those respective resources.  
I created the “message” column in the Activities table thinking i can  
dynamically create the message and store it in DB and extract it for  
the dashboard. All that works fine but now how do I insert the links?

whats the best strategy for this? scrap what I have done and please  
suggest ideas on how you might approach this problem. one thing I DO  
NOT want to do is dynamically generate those messages in the view. I  
just think it will be too much load on the db AND rendering action  
itself as compared to storing the message and applying the links  
dynamically on retrieval somehow.

thoughts? ideas? suggestions?

thanks…

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 3, 2009, 6:06pm UTC](https://www.ruby-forum.com/t/activity-log-messages-with-links-strategy/173121/2 "2009-08-03T18:06:40Z")

</div>

Ram wrote:

> Hi all,
> 
> Im looking to write an activity log as part of the dashboard for one  
> of my apps. The log should show messages like
> 
> “Vinay created the project Acme Inc Website”, “You completed 2 tasks  
> in the project Acme Inc website”
> 
> and so on.
> 
> So i went about creating an activities table with controller, action,  
> user, message and timestamps. Now the messages the user sees in his  
> dashboard should have links on words like “You”, “Vinay”, “Acme Inc  
> Website” and so on such that they link to those respective resources.  
> I created the “message” column in the Activities table thinking i can  
> dynamically create the message and store it in DB and extract it for  
> the dashboard. All that works fine but now how do I insert the links?

Well, you could just generate the whole HTML string and store it, but I  
assume that you want me to see “Vinay” and Vinay to see “you” for the  
same message, so that won’t quite work.

> whats the best strategy for this? scrap what I have done and please  
> suggest ideas on how you might approach this problem. one thing I DO  
> NOT want to do is dynamically generate those messages in the view. I  
> just think it will be too much load on the db AND rendering action  
> itself as compared to storing the message and applying the links  
> dynamically on retrieval somehow.

This may well be premature optimization.

> thoughts? ideas? suggestions?
> 
> thanks…

Take a leaf out of Facebook’s book. Use an intermediate representation  
in the DB: something like “[user 110] created project Acme”. Then parse  
that when the view is created, so that user 110 sees “you” and everyone  
else sees user 110’s name.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 4, 2009, 7:03am UTC](https://www.ruby-forum.com/t/activity-log-messages-with-links-strategy/173121/3 "2009-08-04T07:03:33Z")

</div>

Nice… that seems like a good option. So assuming that im gonna use  
link\_to to generate the HTML, I will have to generate the message in  
either the controller or view right? was hoping i could generate the  
message in the model keeping the controller clean.

anyway, ill get on that.  
anymore ideas or suggestions?

On Aug 3, 9:06 pm, Marnen Laibow-Koser \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 4, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/activity-log-messages-with-links-strategy/173121/4 "2009-08-04T17:17:46Z")

</div>

Ram wrote:

> Nice… that seems like a good option. So assuming that im gonna use  
> link\_to to generate the HTML,

Why are you assuming that? It may be a good idea, or it may not.

> I will have to generate the message in  
> either the controller or view right? was hoping i could generate the  
> message in the model keeping the controller clean.

Generate the intermediate representation in the model and store it in  
the DB. Parse it (probably with a model method, or else a helper) when  
you render the view. I don’t see why you need to put too much in the  
controller.

> anyway, ill get on that.  
> anymore ideas or suggestions?

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 5, 2009, 6:56am UTC](https://www.ruby-forum.com/t/activity-log-messages-with-links-strategy/173121/5 "2009-08-05T06:56:37Z")

</div>

Hi Marnen,

Thats almost what im doing right now. Ive got the message being  
generated in the model alongwith HTML tags for the links (link\_to did  
not work as i was hoping) and I use a helper method to display the  
"You"s and usernames and other such small cosmetics.

Will it be too complicated to generate the links in to helper method?  
Maybe I should throw in a ‘resource\_id’ field into activity\_logs and  
store the id of the task/project upon which an activity is being  
performed. That will help in generating messages on the fly in the  
views. Also, that sounds like a polymorphic relationship entering the  
picture…? Your thoughts?

Thanks,  
Vinay.

On Aug 4, 8:17 pm, Marnen Laibow-Koser \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 13, 2009, 6:18am UTC](https://www.ruby-forum.com/t/activity-log-messages-with-links-strategy/173121/6 "2009-08-13T06:18:13Z")

</div>

On Aug 4, 9:53 pm, Ram [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Marnen,
> 
> Will it be too complicated to generate the links in to helper method?  
> Maybe I should throw in a ‘resource\_id’ field into activity\_logs and  
> store the id of the task/project upon which anactivityis being  
> performed. That will help in generating messages on the fly in the  
> views. Also, that sounds like a polymorphic relationship entering the  
> picture…? Your thoughts?

This sounds very similar to the exact thing I want to get. A user  
activity log with hyperlinks to the various ActiveRecord objects that  
they’ve viewed or created. I created a thread -

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/a5ebe53638c8331f](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/a5ebe53638c8331f)
