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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:04:54+00:00 2026-06-09T05:04:54+00:00

I am just starting on rails and found a problem which I can’t solve.

  • 0

I am just starting on rails and found a problem which I can’t solve. I am creating a simple app with two models (awards and students). :award has_one :student and :student belongs_to :award

I was told that in app/views/awards/ in show.html.erb, replace:

<%= @award.student_id %>

with:

<%= @award.student.given_name %> <%= @award.student.family_name %>

and in index.html.erb, replace:

<%= award.student_id %>

with:

<%= award.student.given_name %> <%= award.student.family_name %>

after this the localhost:3000/students is working fine but localhost:3000/awards is not working and giving following error :-

**NoMethodError in Awards#index**

Showing /home/redblink/rbtest/students/app/views/awards/index.html.erb where line #17 raised:

undefined method `given_name' for nil:NilClass

Extracted source (around line #17):

14:   <tr>
15:     <td><%= award.name %></td>
16:     <td><%= award.year %></td>
17:     <td><%= award.student.given_name %> <%= award.student.family_name %></td>
18:     <td><%= link_to 'Show', award %></td>
19:     <td><%= link_to 'Edit', edit_award_path(award) %></td>
20:     <td><%= link_to 'Destroy', award, method: :delete, data: { confirm: 'Are you sure?' } %></td>

please reply asap with the solution…..

  • 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-09T05:04:56+00:00Added an answer on June 9, 2026 at 5:04 am

    The problem is that there is one of the awards record whose corresponding students record is not present so its returning nil and u can call given_name on nil.

    So you can handle it as:

    Write following:

    <%= award.student ? award.student.given_name : '' %> <%= award.student ? award.student.family_name : '' %>

    instead of

    <%= award.student.given_name %> <%= award.student.family_name %>

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

Sidebar

Related Questions

I am just starting to learn Rails and I'm creating my first project. In
I'm just starting to learn Rails. I created an empty Rails app. And instead
My Rails app is starting to need complicated queries. Should I just start using
Okay so I was just starting this rails app and generated my first model
I am just starting with rails and I have a very simple case. I
I'm just starting out with Ruby/Rails and am wondering what Rails developers use to
I am just starting to write ruby rails. I wrote a controller but is
I'm just starting to tinker with extending the rails framework, and as an experiment,
Preface: I'm a big fan of Netbeans for Rails development. I'm just starting my
I'm just starting out with Rails and ActiveRecord. I feel that anything I want

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.