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 8468789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:02:15+00:00 2026-06-10T16:02:15+00:00

A question that I hope you can answer for a Q&A app. Still very

  • 0

A question that I hope you can answer for a Q&A app. Still very new with Rails. It should be fairly simple but there is a small issue that I run into whenever I am trying to create a list of links to show up that point to a RESTful route from a loop.

Here’s the code for the controller:

users_controller.rb

def list
  @user = User.find(params[:id])
  @users = User.find(:all, :select => :name)
end

def quiz
  @user = User.find(params[:id])
  @users = User.find(:all, :select => :name)
end

Here’s the code for the view:

<% if current_user.admin? %>
  <ul>
    <%- @users.each do |link| %>
      <li><%= link_to link.name, quiz_user_path(@user, @quiz) %></li>
    <% end %>
  </ul>
<% end %>

Here’s the code for the route:

resources :users do 
  get 'quiz', :on => :member
end

What I want to do is generate individual links based on the name of the users and then link to the quiz page for that specific user. I’m pretty sure that something needs to be changed for the code in my view. Right now, all I’m getting is a link that all points to the current user which in this case is user 4. (http://localhost:3000/users/4/quiz)

Thanks for any quick tips to solve 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-10T16:02:17+00:00Added an answer on June 10, 2026 at 4:02 pm

    Currently you are using the same @user instance variable for each link. Instead you need to use the variable set in your loop. The code below should work as expected:

    <% if current_user.admin? %>
      <ul>
        <%- @users.each do |user| %>
          <li><%= link_to user.name, quiz_user_path(user) %></li>
        <% end %>
      </ul>
    <% end %>
    

    I also renamed the variable from link to user, for clarity, since your iterating through users not links.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A minor question that I hope admits of a simple answer that I'll kick
I have a question that is probably very simple, but I cannot find an
I have a question that's so simple I cannot believe I can't answer it
I hope that this one is not going to be ask-and-answer question... here goes:
I've searched far and wide and I hope someone can answer this question. I'm
I have a quick question i hope you guys can answer, i've got a
I hope that this is a quick question to answer. I am developing a
I hope someone can answer this question. How does the UuidCreateSequential method in the
Unfortunately, the answer to this question isn't quite as simple as it sounds... but
I hope that this question has not been asked elsewhere, but I'm having difficulty

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.