module TmLyn class CategoriesController < ApplicationController def index @cats = Category.all end def new @cat = Category.new end def create @cat = Category.new(cat_params) if @cat.save redirect_to categories_path, notice:"Category created" else render :new, status: :unprocessable_entity end end def edit @cat = Category.find(params[:id]) end def update @cat = Category.find(params[:id]) if @cat.update(cat_params) redirect_to categories_path, notice:"Category updated successfully" else render :edit end end private def cat_params params.require(:category).permit(:name) end end end