title: Getting undefined method `errors' for nil:NilClass
body: <p>I'm doing the Ruby on Rails tutorial at <a href="http://guides.rubyonrails.org/getting_started.html" rel="nofollow">http://guides.rubyonrails.org/getting_started.html</a></p>
  
  <p>However when I get to "5.11 Adding Some Validation", after adding the error message to display when I try to create a new post from the index view I get </p>
  
  <p>"undefined method `errors' for nil:NilClass"</p>
  
  <p>This is the error line highlighted.</p>
  
  
  
  <p>I have already created a new Post in my new action in the controller.</p>
  
  <p>Here is the source</p>
  
  <p><b>new.html.erb</b></p>
  
  <pre><code>&lt;h1&gt;New Post&lt;/h1&gt;
    &lt;%= form_for :post, url: posts_path do |f| %&gt;
    &lt;% if @post.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@post.errors.count, "error") %&gt; prohibited this post from being saved:&lt;/h2&gt;
      &lt;ul&gt;
        &lt;% @post.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
      &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
    &lt;p&gt;
      &lt;%= f.label :title %&gt;&lt;br&gt;
      &lt;%= f.text_field :title %&gt;
    &lt;/p&gt;
  
    &lt;p&gt;
      &lt;%= f.label :text %&gt;&lt;br&gt;
      &lt;%= f.text_area :text %&gt;
    &lt;/p&gt;
  
    &lt;p&gt;
      &lt;%= f.submit %&gt;
    &lt;/p&gt;
    &lt;% end %&gt;
  </code></pre>
  
  <p><b>posts_controller.rb</b></p>
  
  <pre><code>class PostsController &lt; ApplicationController
  def new
      @Post = Post.new
  end
  
  def create
      @post = Post.new(post_params)
      if @post.save
          redirect_to @post
      else
          render 'new'
      end
  end
  
  def show
      @post= Post.find(params[:id])
  end
  
  def index
      @posts = Post.all
  end
  
  def edit
      @post = Post.find(params[:id])
  end
  
  def update
      @post = Post.find(params[:id])
  
      if @post.update(post_params)
          redirect_to @post
      else
          render 'edit'
      end
  end
  
  private
      def post_params
          params.require(:post).permit(:title, :text)
      end
  end
  </code></pre>
  
  <p>Thanks.</p>