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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:34:15+00:00 2026-05-28T07:34:15+00:00

This was working just fine, not sure what broke it, but now I’m getting

  • 0

This was working just fine, not sure what broke it, but now I’m getting this error:

undefined method `Name' for nil:NilClass

I’m running Rails 3.1. I have a table called “restaurants”, “lists”, and “list_Items”. The associations are as follows:

class Restaurant < ActiveRecord::Base
  #relations
  has_many :list_items
  has_many :reviews

class List < ActiveRecord::Base
  has_many :list_items, :dependent => :destroy

class ListItem < ActiveRecord::Base
  belongs_to :restaurant
  belongs_to :list

The line that’s giving me the problem is in the view partial that displays my list items

<tr>
  <td><%= list_item.restaurant.Name %> <%= link_to 'X', list_item, :method => :delete, :remote => true %></td>
</tr>

I think this should all work fine, but given the error at top, it’s not recongizing the association such that I can get at the restaurant name. Again, this was working, I don’t know why it’s breaking now…

UPDATE

As Mu correctly pointed out (thanks Mu), the problem isn’t the association, it was the presence of a list_item associated with a deleted restaurant. So, it was running up against a Nil entry.

The above is resolved and now the real question (the question I should have been asking to begin with) is how to ensure this doesn’t happen. What should I change to ensure that a list_item is deleted when the associated restaurant is deleted?

  • 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-28T07:34:16+00:00Added an answer on May 28, 2026 at 7:34 am
    class Restaurant < ActiveRecord::Base
    
      has_many :list_items, :dependent => :destroy
      has_many :reviews
      ...
    
    end
    

    And you are good to go.

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

Sidebar

Related Questions

Im trying to get this working but for some reason it's just not right.
All Rails applications are working just fine until today. I am not sure if
I have been working on this for some time now and just cant quite
I've been working very long on trying to straighten this out, but I just
I am doing a procedure and it's working but I'm not sure if it'll
I'm not sure this is the problem, but it looks like it might be
I'm not sure if this has even been done before, but what I am
I am sure this is a basic answer, but my search powers are not
Not entirely sure why this isn't working. sqlite3 *db; sqlite3_open([databasePath UTF8String], &db); NSString *query;
I am working with zend just recently. I discovered this ViewScript decorator for form

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.