0

I have and app with some question. My links are numbers 1,2,3 ect.

Each of this link is a path to another question. I made that visited link changes color but that option is not good. It's not good because when I once open that link it show it in color which I set for visited link. But when I delete from DB that question and add new it has again number 1 as link and it is shown as visited.

This is part of code where I have done that:

<% @categories.each do |category| %>
    <div id=<%= "box#{category.id}" -%>>
        <h1><%= category.name %></h1>
        <% category.questions.each_with_index do |question, i| %>
        <ul class="question-list" style="display: inline;">
             <li><%= link_to (i + 1), show_path(question_id: question.id) %></li>
        </ul>
<% end %>

This part look like this. below each category are questions.

Category

1 2 3 4

I do not want delete question from database. I only want to delete link.

So if I open question with number 1 and when I go back I want that this number 1 as link disappear and then I will have like this.

Category

2 3 4

Question: How to delete just link name after link is visited?

RubyDigger19
  • 835
  • 13
  • 38
  • You can hide the visited link via css as a:visited { display: none; } . Reference from http://stackoverflow.com/questions/19014213/how-to-hide-visited-links-after-a-click-to-button – Ranjeet Singh May 14 '16 at 11:41

2 Answers2

0

If you can change the color then you can easily do a display:none. Make a class for the visited links and for that class put the display: none.

Wijan Ruiz
  • 33
  • 1
  • 6
0

There are two ways to do this.

  1. Css solution (comment from Ranjeet Singh)

    .question-list a:visited    {    display:none;    }
    
  2. JQuery solution

    $('.question-list a').click(function(e) {
    e.preventDefault();
    $(this).hide();    });
    

    (if it's not a SPA (single page application) may you have to save the state (WebStorage)

Cyril Iselin
  • 596
  • 4
  • 20
  • This works but it is not what I need. I need first open link, then when I go back link need's to disappear. – RubyDigger19 May 14 '16 at 12:38
  • May you can store on the click event the clicked link index, and on document ready event, you can hide the stored links... – Cyril Iselin May 14 '16 at 12:40
  • Have a look at the WebStorage link, this will allow you to save informations localy (still available after navigate back, close browser...). One idea is to store the "clicked link" and on document ready, you can disable the allready clicked links. ( https://learn.jquery.com/using-jquery-core/document-ready/ ) – Cyril Iselin May 14 '16 at 13:04
  • Looked this link.. But don't know where to start honestly.. I'll figure something out I guess – RubyDigger19 May 14 '16 at 14:40