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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:40:07+00:00 2026-06-02T13:40:07+00:00

This my first time asking a question so please go easy one me :-p

  • 0

This my first time asking a question so please go easy one me :-p

I am following the examples on http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials (Section 3.4.5 Rendering Collections) for rendering collections using partials. The code looks simple, but clearly I am missing something.

models/expert.rb contains the line:

attr_accessible :name

experts_controller.rb contains the following line in the index method:

@experts = Expert.all

views/experts/index.html.erb contains the following line:

<%= render :partial => "expert", :collection => @experts %>

views/experts/_expert.html.erb contains:

<%= expert.name %>

Upon viewing the index page in my browser I get the following error:

NoMethodError in Experts#index
undefined method `name' for nil:NilClass

I have been working on this for an hour and am completely stumped :-/ What little thing am I missing?

—Clarification—

Running ‘<%= debug @experts %>’ within index.html.erb produces the following output:

- !ruby/object:Expert
attributes:
    id: 1
    name: Bob Smith
    slug: bob-smith
    created_at: '2012-03-11 18:37:11.791118'
    updated_at: '2012-03-11 18:55:58.179629'
  changed_attributes: {}
  previously_changed: {}
  attributes_cache: {}
  marked_for_destruction: false
  destroyed: false
  readonly: false
  new_record: false
- !ruby/object:Expert
  attributes:
    id: 2
    name: Steve Kamp
    slug: steve-kamp
    created_at: !!null 
    updated_at: !!null 
  changed_attributes: {}
  previously_changed: {}
  attributes_cache: {}
  marked_for_destruction: false
  destroyed: false
  readonly: false
  new_record: false
  • 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-02T13:40:09+00:00Added an answer on June 2, 2026 at 1:40 pm

    The exception almost certainly means that there are no experts, so @experts is an empty array. Have you created any expert records yet?

    Also, just so you’ll know, to render a collection of objects the way you’re doing there’s a nice shortcut:

    render @experts
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time asking a question, please be gentle! I have a
This is my first time asking a question in this website so please bear
First of all this is the first time I am asking a java question
First time using this service for a question. I hope I am not asking
This is my first time asking my question at stackoverflow. I'm working on a
this is my first time asking a question here so apologies if I am
this is my first time asking a question here so I hope I am
Hey, first time asking a question on Stack Overflow, so go easy on me!
This is the first time i'm asking a question here at stack overflow so
Well this is not the first time im asking these question here but I

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.