title: NameError in Category#index
body: <p>Below is my category controller :</p>
  <pre><code>class CategoryController &lt; ApplicationController
  
    def index  
      @category = Category.all    
    end
  
    def new
      @category = Category.new
    end
  
    def create
      @category = Category.new(params[:category])
      @category.save
      redirect_to @category   
    end
  
    def show
      @category = Category.find(params[:id])
    end
  
    private
  
      def category_params
        params.require(:category).permit(:name)
      end
  
      def find_post
        @category = Category.find(params[:id])
      end
  
  end
  </code></pre>
  <p>This is my index page where I want to show all my categories</p>
  <pre><code>&lt;h1&gt;ALL CATEGORIES&lt;/h1&gt;
  &lt;% @category.each do |c|%&gt;
    &lt;ul&gt;&lt;%= link_to c.name, categories_path(category) %&gt;&lt;/ul&gt; 
  &lt;% end %&gt;
  &lt;%= link_to &quot;Add Category&quot;, new_category_path %&gt;  
  </code></pre>
  <p>These are the routes I have set for this controller</p>
  <p>Rails.application.routes.draw do</p>
  <pre><code>root 'category#index'
  post '/category' =&gt; 'category#create'
  get '/category/new' =&gt; 'category#new', as:'new_category'
  get '/category/:id' =&gt; 'category#show', as:'categories'
  </code></pre>
  <p>end</p>
  <p>Why I am getting this name error and how can I fix it ?</p>
  <blockquote>
  <p>undefined local variable or method <code>category' for </code>enter code
  here<code>#&lt;#&lt;Class:0x00007feddc03ad50&gt;:0x00007fede47f8378&gt;</code> Did you mean?
  <code>@category</code></p>
  </blockquote>