title: 'NoMethodError in Posts#index' error in the index page
body: <blockquote>
    <p>This is my index.html.erb file</p>
  </blockquote>
  
  <pre><code>&lt;% @posts.each do |post| %&gt;
    &lt;div class="post_wrapper"&gt;
       &lt;h2 class="title"&gt;&lt;%= link_to post.title, post %&gt;&lt;/h2&gt;
       &lt;p class="date"&gt;&lt;%= post.created_at.strftime("%B %d, %Y") %&gt;&lt;/p&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I want to change the line</p>
  
  <pre><code>&lt;p class="date"&gt;&lt;%= post.created_at.strftime("%B %d, %Y") %&gt;&lt;/p&gt;
  </code></pre>
  
  <p>to <code>&lt;p class="date"&gt;Submitted &lt;%= time_ago_in_words(@post.created_at) %&gt; Ago&lt;/p&gt;</code> but it's throwing up errors. This line is working well in show page but got errors in the index page.</p>
  
  <blockquote>
    <p>below is my post_controller.rb file</p>
  </blockquote>
  
  <pre><code>class PostsController &lt; ApplicationController
  before_action :authenticate_user!, except: [:index, :show]
  before_action :correct_user,       only: [:destroy, :edit]
  
  
  def search
        if params[:search].present?
            @posts = Post.search(params[:search])
        else
            @posts = Post.all
        end   
    end
  
    def index
        @posts = Post.all.order('created_at DESC')        
    end
  
    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 edit
        @post = Post.find(params[:id])        
    end
  
    def update
        @post = Post.find(params[:id])
  
        if @post.update(params[:post].permit(:title, :date, :time, :location))
            redirect_to @post
        else
            render 'edit'
        end   
    end
  
    def destroy
        @post = Post.find(params[:id])
        @post.destroy
  
        redirect_to root_path     
    end
  
    def upvote
      @post = Post.find(params[:id])
      @post.upvote_by current_user
      redirect_to :back
    end
  
  
    private
    def post_params
        params.require(:post).permit(:title, :date, :time, :location)
    end
  
    def correct_user
        @post = current_user.posts.find_by(id: params[:id])
        if @post.nil?
          flash[:alert] = "Not your post!"
          redirect_to :back
        end
      end
  end
  </code></pre>
  
  <blockquote>
    <p>and here's my show.html.erb file,</p>
  </blockquote>
  
  <pre><code>&lt;div id="post_content"&gt;
  &lt;h1 class="title"&gt;
      &lt;%= @post.title %&gt;
  &lt;/h1&gt;
  
  &lt;p class="date"&gt;
      Submitted &lt;%= time_ago_in_words(@post.created_at) %&gt; Ago
      &lt;!-- To show edit &amp; delete for sign_in user
      &lt;% if user_signed_in? %&gt;
      | &lt;%= link_to 'Edit', edit_post_path(@post) %&gt;
      | &lt;%= link_to 'Delete', post_path(@post), method: :delete, data: { confirm: 'Are you sure?' } %&gt;
      &lt;% end %&gt;
      --&gt;
  &lt;/p&gt;
  
  &lt;p class="date"&gt;
      &lt;%= @post.date %&gt;
  &lt;/p&gt;
  
  &lt;p class="time"&gt;
      &lt;%= @post.time %&gt;
  &lt;/p&gt;
  
  &lt;p class="location"&gt;
      &lt;%= @post.location %&gt;
  &lt;/p&gt;
  
  &lt;div id="comments"&gt;
  
    &lt;div class="btn-group pull-left"&gt;
      &lt;%= link_to like_post_path(@post), method: :put, class: "btn btn-default" do %&gt;
        &lt;span class="glyphicon glyphicon-heart"&gt;&lt;/span&gt;
        &lt;%= @post.get_upvotes.size %&gt;
      &lt;% end %&gt;&amp;nbsp;&amp;nbsp;
    &lt;/div&gt; 
  
      &lt;h2&gt;&lt;%= @post.comments.count %&gt; Comments&lt;/h2&gt; 
      &lt;%= render @post.comments %&gt;
  
      &lt;h3&gt;Add a comment:&lt;/h3&gt;
      &lt;%= render "comments/form" %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>