I'd like to modify the contents of a controller's index.html.erb
page based on whether or not a user has previously viewed records associated with that controller.
In my particular case, I have an Item model, Items controller, and an Items view. The Item's view index.html.erb
displays a link to each Item. I need to setup this view such that if an item has been viewed previously, then its link on index.html.erb
would be in italics. If it had not been viewed, the link would be in boldface.
Visually, this approach is similar to an e-mail inbox, where items that have not been viewed have subject headings listed in bold face and viewed items have a regular font weight.
My question is similar to this previous stack overflow post; however, that post provides a general answer related to database structure. I'm curious to know if there is a ''Rails way'' to achieve this behavior that I am missing. If the linked post is appropriate, can anyone offer suggestions as how to achieve the posts' recommended solution using Rails?
I could rely on the browser and use the appropriate CSS to style visited and unvisited URLs, but for other reasons relevant to my project (but not this question, really) I'd rather have a solution that relies on Rails, hooks, and/or the database. I'm also up for other solutions (e.g., jQuery-based) if there's no straightforward Rails way of doing this.