vendredi 3 juillet 2020

NameError in Category#index

This is my category controller 
class CategoryController < 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
This is my index page where i want to show all my categories
<h1>ALL CATEGORIES</h1>
<% @category.each do |c|%>
  <ul><%= link_to c.name, categories_path(category) %></ul> 
<% end %>
<%= link_to "Add Category", new_category_path %>  

These are the routes i have set for this controller

Rails.application.routes.draw do

root 'category#index'
post '/category' => 'category#create'
get '/category/new' => 'category#new', as:'new_category'
get '/category/:id' => 'category#show', as:'categories'

end Why i am getting this name error? undefined local variable or method category' for enter code here`#<#Class:0x00007feddc03ad50:0x00007fede47f8378> Did you mean? @category

Aucun commentaire:

Enregistrer un commentaire