I "have a nil object, when I didn't expect it"

I’m on page 340 in the Simply Rails book, but when I was trying to test the Shovell application, the application catches an error from a previous part of the book.
The error is:
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.size

Here’s the problematic code:
1: <h2>
2: <%= “Showing #{ pluralize(@stories.size, ‘story’) }” %>
3: </h2>
4: <% render :partial => @stories %>

There is something wrong with line 2. I am too unfamiliar with Ruby code to figure it out.

in the controller you an instance variable @story but you are referencing it as @stories, have you tried to reference it as @story in he view as the controller is not passing any @stories to the view therefor “nil.size”

Let me know if you solved it

Sure, I will post it here:


class StoriesController < ApplicationController
  before_filter :login_required, :only => [ :new, :create]
  def index
    @story = Story.find :all,
      :order => 'id DESC',
      :conditions => 'votes_count >= 5'
  end
  def new
    @story = Story.new
  end
  def create
    @story = @current_user.stories.build params[:story]
    @story = Story.new(params[:story])
    if @story.save
      flash[:notice] = 'Story submission succeeded'
      redirect_to stories_path
    else
      render :action => 'new'
    end
  end
  def show
    @story = Story.find(params[:id])
  end

end

The only thing that I can see would create the nil object is the condition on the find method. You are limiting the result set to stories with at least five votes. Try either lowering the condition to just one vote or going to the console to make sure you have at least one story that meets the five vote minimum.

Kelp, the problem may actually be in your controller. The instance variable @stories seems to be nil, or none existant when the view goes to reference it. Can you show me the code in your stories controller?