SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Partial works one time, not another

    Working on "Shovell", I have gotten to the 2 index pages, Front Page and Upcoming Stories. The "Front Page" works fine. The "upcoming Stories" doesn't.

    The problem lies in the _story.rhtml file.
    Code:
    <div id="story">
        <h3><%= link_to story.name, 
                       story_url(:permalink => story.permalink) %></h3>
    	<p>
    	 Submitted by: <%= story.user.login %> | 
    	 Score: <%= story.votes_count %>
        </p>
      </div>
    This same file is used both by "index" (or Front Page) and "bin" or (upcoming stories). The only difference in code with the two controllers is the choice conditions for the sql. The "bin" then uses the index.rhtml file for output just like the "index".

    Here is the result:
    Code:
    Showing app/views/story/_story.rhtml where line #4 raised:
    
    You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.login
    
    Extracted source (around line #4):
    
    1:   <div id="story">
    2:     <h3><%= link_to story.name, story_url(:permalink => story.permalink) %></h3>
    3: 	<p>
    4: 	 Submitted by: <%= story.user.login %> | 
    5: 	 Score: <%= story.votes_count %>
    6:     </p>
    7:   </div>
    This is straight out of the book - Strange that it works one way and not the other. Does anyone have any answers to this problem?
    ---------------------------
    Conrad Parvin
    Web Development: http://www.parvin-associates.com
    Web Hosting: http://www.integrityhosting.biz

  2. #2
    l 0 l silver trophybronze trophy lo0ol's Avatar
    Join Date
    Aug 2002
    Location
    Palo Alto
    Posts
    5,329
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It looks like you have an issue here:

    Code:
    Submitted by: <&#37;= story.user.login %>
    It's having problems trying to grab story.user (you're trying to call .login on nil, which means that story.user == nil when you call it). Does each story correctly associate with a user? That's the common problem here: user_id in that story record is non-existent or points to a user that isn't in the database, that type of thing.

  3. #3
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Yes, but

    Quote Originally Posted by lo0ol View Post
    It looks like you have an issue here:

    Code:
    Submitted by: <&#37;= story.user.login %>
    It's having problems trying to grab story.user (you're trying to call .login on nil, which means that story.user == nil when you call it). Does each story correctly associate with a user? That's the common problem here: user_id in that story record is non-existent or points to a user that isn't in the database, that type of thing.
    I know that is what is is appearing to happen, but the only difference between this rendering of the "Upcoming Stories" (This page) index.rhtml and the "Front Page" rendering is the condition in the sql. With the offending code commented out, it lists 7 items, so the sql is NOT returning nil. Only these fields do not work. I have looked at the database and all stories fields are populated. (I use MySql Front)

    --------------
    Later: I checked MySql Front this morning and you are right - There was a user missing from a record. Fixed that and it now works.

    Thanks to all who pondered this problem.
    Last edited by cparvin; Sep 2, 2007 at 11:51. Reason: Later Information
    ---------------------------
    Conrad Parvin
    Web Development: http://www.parvin-associates.com
    Web Hosting: http://www.integrityhosting.biz


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •