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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:26:32+00:00 2026-05-15T08:26:32+00:00

UPDATE my show function def show @contact = Contact.find(params[:id]) @data = Register.all :include =>

  • 0

UPDATE

my show function

def show
@contact = Contact.find(params[:id])
@data = Register.all :include => {:session =>[:term, :course]}  , :conditions => ["contact_id = ?", params[:id]]
respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @contact }
end

end

Models

class Register < ActiveRecord::Base
 belongs_to :session
 belongs_to :contact
end

class Session < ActiveRecord::Base
 belongs_to :term  
 belongs_to :course
 has_many :registers
 has_many :contacts, :through => :registers
end

Hi,

I am kind of new to ruby on rails. I want to display the following –

- !ruby/object:Register 
attributes: 
 created_at: 2010-06-20 11:39:06
 updated_at: 2010-06-20 11:39:06
 session_id: "32"
 contact_id: "601"
 id: "1"
attributes_cache: {}

session: !ruby/object:Session 
attributes: 
  created_at: 2010-06-19 10:16:13
  term_id: "26"
  updated_at: 2010-06-19 10:16:13
  id: "32"
  course_id: "4"
attributes_cache: {}

course: !ruby/object:Course 
  attributes: 
    created_at: 2010-05-30 14:36:24
    updated_at: 2010-05-30 14:36:28
    course_name: Beginner
    id: "4"
    course_type: Running
  attributes_cache: {}

term: &id001 !ruby/object:Term 
  attributes: 
    number: "1"
    start_date: "2010-06-19"
    created_at: 2010-06-19 10:16:13
    updated_at: 2010-06-19 10:16:13
    id: "26"
  attributes_cache: {}

I think I’m doing it wrong

    <% @data.Register.each do |c| %>
    <tr>
        <td><%=h c.Term.number %></td>
        <td><%=h c.Course.course_name %></td>
   </tr>
   <% end %>

Thanks

  • 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-15T08:26:33+00:00Added an answer on May 15, 2026 at 8:26 am

    The Ruby on Rails convention is that classes are capitalized, instances of a class are not.

    If a model Registration includes a declaration

    has_one term
    

    Then you’d access the term by using

    registration = Registration.find xxx  # get an instance of the Registration model
    registration.term # access the associated term model
                      # do not use registration.Term
    

    So…

    1) You need to show us your controller code. And your ActiveRecord class files–have you properly defined the relationships using belongs_to, has_many declarations?

    2) Your sw should be more like:

    # Controller
    def show
       # Shows all the registrations for person_id
       # args: params['person_id']
       @registrations = Register.find_all_by_person_id(params['person_id'].to_i_
    end
    
    # View 
    
    <% @registrations.each do |r| %>
    <tr>
        <td><%=h r.term.number %></td>
        <td><%=h r.course.course_name %></td>
    </tr>
    <% end %>    
    

    ADDED

    Also, be very careful about naming a model “session” — the potential problem is that CGI sessions may be stored into the model Session if db-backed sessions are turned on.

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

Sidebar

Ask A Question

Stats

  • Questions 478k
  • Answers 478k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try putting in #undef __STRICT_ANSI__ before including stdio.h May 16, 2026 at 5:34 am
  • Editorial Team
    Editorial Team added an answer You can't make an application not resize a 64x64 image… May 16, 2026 at 5:34 am
  • Editorial Team
    Editorial Team added an answer If I read your question correctly, you're not really looking… May 16, 2026 at 5:34 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.