title: Getting undefined method `errors' for nil:NilClass Ruby on Rails Guide
body: <p>Okay, I've been searching for a question here thats exactly the same as mine and I can't find one, so I'm forced to ask it myself. I'm following the guide on here: <a href="http://guides.rubyonrails.org/getting_started.html" rel="nofollow">http://guides.rubyonrails.org/getting_started.html</a></p>
  
  <p>I ran into this error saying: "undefined method `errors' for nil:NilClass" for my Edit Article page.</p>
  
  <p>Here is my extracted source:</p>
  
  <pre><code> &lt;h1&gt;Editing article&lt;/h1&gt;
   &lt;%= form_for :article, url: articles_path(@article), method: :patch do |f| %&gt;
     &lt;% if @article.errors.any? %&gt;
       &lt;div id="error_explanation"&gt;
         &lt;h2&gt;&lt;%= pluralize(@article.errors.count, "error") %&gt; prohibited
              this article from being saved: &lt;/h2&gt;
  </code></pre>
  
  <p>And here is my trace: </p>
  
  <p>app/views/articles/edit.html.erb:4:in block in _app_views_articles_edit_html_erb___778692675__618464548</p>
  
  <p>app/views/articles/edit.html.erb:3:in _app_views_articles_edit_html_erb___778692675__618464548</p>
  
  <p>Here is my action Controller</p>
  
  <pre><code>class ArticlesController &lt; ApplicationController
  def new
      @article = Article.new
  end
  
  def edit
      @articles = Article.find(params[:id])
  end
  
  def create
      @article = Article.new(article_params)
  
      if @article.save
          redirect_to @article
      else
          render 'new'
      end
  end
  
  def show
      @article = Article.find(params[:id])
  end
  
  def index
      @articles = Article.all
  end
  
  def update
      @article = Article.find(params[:id])
  
      if @article.update(article_params)
          redirect_to @article
      else
          render 'edit'
      end
  end
  
  private
      def article_params
          params.require(:article).permit(:title, :text)
      end
  
  
   end
  </code></pre>
  
  <p>And here is my edit.html.erb</p>
  
  <pre><code>&lt;h1&gt;Editing article&lt;/h1&gt;
  
  &lt;%= form_for :article, url: articles_path(@article), method: :patch do |f| %&gt;
    &lt;% if @article.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
    &lt;h2&gt;&lt;%= pluralize(@article.errors.count, "error") %&gt; prohibited this article 
          from being saved: &lt;/h2&gt;
       &lt;ul&gt;
          &lt;% @article.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>