SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Nil object when you didn't expect it

    Hi All,

    I'm working through o'reilly's "Up and Running" book, trying to build the photo gallery, but when i go to view a slide show i get this error

    You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.filename

    I assume it's a problem with the Slideshow model, and the relationships i have created.

    I my slideshow.rb i have this
    Code Ruby:
      has_many :photos, :through => :slides
      has_many :slides, :order => :position
    i've created a slideshow helper to display the thumbnails and i think this is where the problem is. for some reason photo = nil
    Code Ruby:
     def thumbnail_tag(slide)
        image_tag "photos/#{slide.photo.filename}"  if slide
      end

    This is list method in my slideshow controller
    Code Ruby:
     def list
        @slideshow_pages, @slideshows = paginate :slideshows, :per_page => 10
      end
    Finally in list.rhtml file for listing all my slideshows i have this
    Code Ruby:
    <% for slideshow in @slideshows %>
    	<div id="slideshow-summary">
    		<div id="slideshow-caption">
    			<%= slideshow.name %>
    			<small>(<%= slideshow.slides.size %> slides)</small>
    		</div>
    		<div id="slideshow-thumbnails">
    			<%= thumbnail_tag slideshow.slides[0] %>
    			<%= thumbnail_tag slideshow.slides[1] %>
    			<%= thumbnail_tag slideshow.slides[2] %>
    			&nbsp;<strong>...</strong>
    		</div>
    		<div id="slideshow-controls">
        <%= link_to 'Play', :action => 'show', :id => slideshow %></td>
        <%= link_to 'Edit', :action => 'edit', :id => slideshow %></td>
        <%= link_to 'Destroy', { :action => 'destroy', :id => slideshow }, :confirm => 'Are you sure?' %>
     
    		</div>
    </div>
    <% end %>


    I can't figure out for the life of why this isn't working, and it's driving me nuts. Sorry for such a long post, but i'd appreciate any help.

    I have Patrick's book too, and i think it's much better than the o'reilly one i have, but i just wanted to build a photo gallery instead of news sharing site.

    Thanks,
    John

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You evidently have slides that don't have a photo.

    image_tag "photos/#{slide.photo.filename}" if (slide and slide.photo)

    Edit: scratch that, none of your slides have a photo ... they have photos.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so you're saying one of the ralationships in one of my models is wrong? thanks for the reply that's going to narrow down where i need to go digging.

  4. #4
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never mind! I read your code wrong!

    So Slide belongs_to :photo, :slideshow ?
    And you are sure each slide does in fact have a photo?
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  5. #5
    SitePoint Zealot lord's Avatar
    Join Date
    Nov 2003
    Location
    sLOVEnia
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heya

    well maybe you already figure out what's the problem (error) in your code ...

    here is one tip:
    try to look in your sometable_controller.rb - if you use any protected methods, then put it at the end of your controller file.


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
  •