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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:01:44+00:00 2026-05-17T19:01:44+00:00

I am using Rails 3 beta 4. I have the following models: class Player

  • 0

I am using Rails 3 beta 4.

I have the following models:

class Player < ActiveRecord::Base
has_many :players_items, :dependent => :destroy 
has_many  :items, :through => :players_items
end

class PlayersItem < ActiveRecord::Base
  belongs_to :player 
  belongs_to :item  
end

class Item < ActiveRecord::Base
  has_many :players_items, :dependent => :destroy
  has_many :players, :through =>  :players_items
end

In the players_controller

def items
    @player = Player.find(params[:id])
    @player_items = @player.items
  end

I have the following attributes

--Items Model--
Item_id:Integer
Name:String
Cost:Integer
Description:Text

--PlayersItem Model--
Item_id:Integer
Player_id:Integer
Total:Integer
Traded:Integer

I am trying to print out all the items associated with a player and for each item print out the “Name”, “Cost”, “Description”, “Total”, and “Traded” values.

When I call @player_items in the items.html.erb, I can only access the attributes associated with the Item Model and not any of the attributes associated with PlayersItem model.

I am trying to access the attributes from both the items model and players_items model in the same “call” similar to SQL Join Statement like this

SELECT * FROM players_items INNER JOIN items ON players_items.item_id=items.id  
WHERE players_items.player_id = "@player"

Is this possible?

  • 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-17T19:01:44+00:00Added an answer on May 17, 2026 at 7:01 pm

    Used in the controller

    @player = Player.find(params[:id], :include => [:items,:players_items])
    

    And in the view

    @player.players_items.each do |player| 
    puts "#{player.name}: #{player.player.item.description} cost:#{player.item.cost}"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using rails beta 3 and I have a erb page named index.html.erb
Now that Rails 3 beta is out, I thought I'd have a look at
I have 3 models: Category, Account, and SubAccount The relations are: Accounts has_many :sub_accounts
I have both Rails 2.3.4 and Rails 3.0.0.beta installed on my local machine. I
I'm using the Rails3 beta, will_paginate gem, and the geokit gem & plugin. As
I'm creating a new web application (Rails 3 beta), of which pieces of it
Hello I have both Rails2 and Rails3(beta 3) installed by Ruby Gems. Everything right
In production, I maintain two sites - beta and release. Each points to a
I've been trying to solve this problem for a couple of hours but I
I would like to create a mechanism for a User to keep track of

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.