Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:58:29+00:00 2026-06-06T21:58:29+00:00

I’d like to modify the contents of a controller’s index.html.erb page based on whether

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:58:33+00:00Added an answer on June 6, 2026 at 9:58 pm

    Honestly, it seems like option 1 of the link you mentioned is the most “Rails way” of doing it. You make a model called a View, which has an item_id and a user_id. I’d say the most important thing is making a View resource.

    Update: So let’s say you want to mark an item as viewed if the user has accessed Items#show for that item. It’s easy enough — in Items#show, before you render that page’s view, do something like this:

    View.create(item_id: params[:id], user_id: current_user.id)
    

    If you’re worried about current_user not being logged in or something like that, you can either make a before_filter on Items#show to log the user in (if you require that he be logged before he views an item) OR just create the view conditionally:

    if current_user
      View.create(item_id: params[:id], user_id: current_user.id)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
i got an object with contents of html markup in it, for example: string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.