I've got a ruby on rails application and am trying to save category data to the system, but whenever I click save I get the error:
NoMethodError in CategoriesController#create
undefined method `category' for #<Category id: nil, genre: "", created_at: nil, updated_at: nil>
Extracted source (around line #29):
27 def create
28 @category = Category.new(category_params)
29 if @category.save
30 redirect_to @category, notice: 'Category was successfully created.'
31 else
32 render action: 'new'
Rails.root: C:/Sites/week_15/New/my_bookshop_test2 _basic
This is my code in the categories_controller.rb:
class CategoriesController < ApplicationController
before_action :set_category, only: [:show, :edit, :update, :destroy]
def new
@category = Category.new
end
def create
@category = Category.new(category_params)
if @category.save
redirect_to @category, notice: 'Category was successfully created.'
else
render action: 'new'
end
end
Can someone please help me.