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

  • SEARCH
  • Home
  • 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 3405788
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:32:54+00:00 2026-05-18T05:32:54+00:00

Newbie question here! I’m building a simple application that allows users to create and

  • 0

Newbie question here! I’m building a simple application that allows users to create and accept challenges. I want to list on one page all challenges, as well as just the challenges the user has accepted. I’m having a bit of trouble doing the latter because I can’t manage to pull in the name of the challenge a user has accepted in my view.

My schema looks like this:

create_table "challenge_lists", :force => true do |t|
t.string   "name"
t.date     "created_on"
t.datetime "created_at"
t.datetime "updated_at"
t.integer  "user_id"
end

create_table "accepted_challenges", :force => true do |t|
t.integer  "user_id"
t.integer  "challenge_list_id"
t.date     "date_accepted"
t.datetime "created_at"
t.datetime "updated_at"
end

Models / Associations:

class ChallengeList < ActiveRecord::Base
has_one :user
has_many :accepted_challenges
end

class AcceptedChallenge < ActiveRecord::Base 
belongs_to :user
belongs_to :challenge_list
has_many :updates
end

Controller:

def index
@challenge_lists = ChallengeList.all
@user_challenges = current_user.accepted_challenges.find(:all, :include => :challenge_list)

respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @challenge_lists }
end

I would like to be able to call user_challenges.name and get back the name of the user’s accepted challenges. Any ideas?

  • 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-05-18T05:32:54+00:00Added an answer on May 18, 2026 at 5:32 am

    You are pretty close, but it seems the problem is that you try to get the name of the collection of challenges. If you only want to extract the names you could do like this:

    >> @user_challenges.map(&:name)
    => ["name1", "name2", "name3"]
    

    But if you want to print it in your views, you would probably be better of with using a block:

    <h1>Challenges for: <%= current_user.name %></h1>
    <% @user_challenges.each do |challenge| %>
    <p><%= challenge.name %></p>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie question here, is there any inbuilt PHP tag that can be used to
R newbie question here. I have a list called dbdata . Normally I use
Ok, here goes a newbie question: //function removes characters and spaces that are not
Pardon the dumb newbie question here; web programming isn't my forte... (blush) I have
Here is one more newbie question: require 'tasks/rails' I saw this line in Rakefile
This is sort of SQL newbie question, I think, but here goes. I have
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
This is a sql newbie question. Basically, I want an extra column to return
Newbie question here. I'm in the beginning stages of laying out a site in
Newbie question here. I have a web form with a text area and naturally

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.