title: "undefined method `errors' for nil:NilClass" when calling on errors method
body: <p>I am currently teaching myself some RoR and doing the tutorial, but adding some nicer layout and stuff with bootstrap and I am running into a problem which I cant figure out.</p>
  
  <p>I am trying to do the validation part (<a href="http://guides.rubyonrails.org/getting_started.html#adding-some-validation" rel="noreferrer">http://guides.rubyonrails.org/getting_started.html#adding-some-validation</a>), but when I use:</p>
  
  <pre><code>&lt;% @post.errors.any? %&gt;
  </code></pre>
  
  <p>I get this message:</p>
  
  <pre><code>undefined method `errors' for nil:NilClass
  Extracted source (around line #9):
  &lt;legend&gt;&lt;h1&gt;Add Post&lt;/h1&gt;&lt;/legend&gt;
  
  &lt;%= form_for :post, url: posts_path, html: {class: 'form-horizontal'} do |f| %&gt;
        &lt;% if @post.errors.any? %&gt;
          &lt;div id="errorExplanation"&gt;
  </code></pre>
  
  <p>Nothing works and I even copied and pasted the parts from the tutorial.</p>
  
  <p>Here is the code for the view:</p>
  
  <pre><code>&lt;p&gt; &lt;/p&gt;
  
  &lt;div class="span6"
  
  &lt;fieldset&gt;
      &lt;legend&gt;&lt;h1&gt;Add Post&lt;/h1&gt;&lt;/legend&gt;
  
      &lt;%= form_for :post, url: posts_path, html: {class: 'form-horizontal'} do |f| %&gt;
            &lt;% if @post.errors.any? %&gt;
              &lt;div id="errorExplanation"&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;div class="control-group"&gt;
              &lt;%= f.label :title, :class =&gt; 'control-label' %&gt;
              &lt;div class="controls"&gt;
                  &lt;%= f.text_field :title, :class =&gt; 'span4' %&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="control-group"&gt;
              &lt;%= f.label :content, :class =&gt; 'control-label' %&gt;
              &lt;div class="controls"&gt;
                  &lt;%= f.text_area :content, :rows =&gt; '7', :class =&gt; 'input-block-level' %&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-actions"&gt;
              &lt;%= f.submit "Add Post", :class =&gt; 'btn btn-success' %&gt;
              &lt;%= link_to "Cancel", posts_path, :class =&gt; 'btn', :style =&gt; 'float:right;' %&gt;
          &lt;/div&gt;
      &lt;% end %&gt;
  &lt;/fieldset&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>And my posts_controller:</p>
  
  <pre><code>class PostsController &lt; ApplicationController
  
      def new
      end
  
      def create
          @post = Post.new(params[:post].permit(:title, :content))
  
          if @post.save
              redirect_to @post
          else
              render 'new'
          end
      end
  
      def show
          @post = Post.find(params[:id])
      end
  
      def index
          @posts = Post.order("created_at desc")
      end
  
      private
          def post_params
              params.require(:post).permit(:title, :content)
          end
  
  end
  </code></pre>
  
  <p>What am I missing? Thanks in advance!</p>