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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:28:24+00:00 2026-05-28T05:28:24+00:00

I´m trying to make a User – Infos association where my User has_many Infos.

  • 0

I´m trying to make a User – Infos association where my User has_many Infos.

I´m trying to call my User Infos on the index form from Users.

By calling <%= user.infos %> on my index.html.erb (Users) it returns me all datas from the Infos table like this:

[#<Info id: 2, name: "Thales Miguel", date: "1989-07-14", area: "An\xC3\xA1lise de Sistemas", comment: "Analista j\xC3\xBAnior de sistemas.", user_id: 1, created_at: "2012-01-16 15:54:29", updated_at: "2012-01-16 15:54:29">]

I assumed that by doing <%= user.infos.comment %> it would return me the “comment” from that user, but all I get is this error:

undefined method `comment' for #<ActiveRecord::Relation:0x3b8ebe8>

What am I doing wrong?

infos_controller:

class InfosController < ApplicationController

  def create
    @user = User.find(params[:user_id])
    @info = @user.infos.create(params[:info])
    redirect_to user_path(@user)
  end

  def destroy
    @user = User.find(params[:user_id])
    @info = @user.infos.find(params[:id])
    @info.destroy
    redirect_to user_path(@user)
  end

  def new
    @user = User.new
    @user.build_info    
end

end

info model:

class Info < ActiveRecord::Base
  belongs_to :user
end

user model:

class User < ActiveRecord::Base
  validates :login,    :presence => true
  validates :password, :presence => true,
                       :length   => {:minimum => 5}

  has_many :infos, :dependent => :destroy

end
  • 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-28T05:28:25+00:00Added an answer on May 28, 2026 at 5:28 am

    This:

    [#<Info id: 2, name: "Thales Miguel", date: "1989-07-14", area: "An\xC3\xA1lise de Sistemas", comment: "Analista j\xC3\xBAnior de sistemas.", user_id: 1, created_at: "2012-01-16 15:54:29", updated_at: "2012-01-16 15:54:29">]
    

    is an array. You have to choose one of the objects. You can’t call an attribute value without selecting one of theses objects. Okay, in this case there is only one object but that doesn’t matter.

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

Sidebar

Related Questions

Im new to django and trying to make a user registration form with few
Im trying to make an operation of creating user network based on call detail
I'm trying to make a form for updating user accounts in Django that is
Here is jsfiddle ! I am trying to make user page where he can
I'm trying make a login window where a user is prompted to enter their
I am trying to make my own user control and have almost finished it,
I am trying to make the same user interface to preview image like on
So I'm trying to make a custom user control for a Windows Phone 7
Trying to make an xna game, where the user needs to tap to stop
I am trying to make a button for the user where he will be

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.