Class: CategoriesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CategoriesController
- Includes:
- Pagy::Backend
- Defined in:
- app/controllers/categories_controller.rb
Overview
This controller manage the views refering to Category model
before_action :ApplicationController#powered_in!
before_action :#set_category, only: [:edit, :update, :destroy]
Instance Method Summary collapse
-
#create ⇒ Object
POST /categories.
-
#destroy ⇒ Object
DELETE /categories/1.
-
#edit ⇒ Object
GET /categories/1/edit.
-
#index ⇒ Object
GET /categories.
-
#list ⇒ Object
GET /categories/list.
-
#new ⇒ Object
GET /categories/new.
-
#update ⇒ Object
PATCH/PUT /categories/1.
Methods inherited from ApplicationController
#admin_in!, #doctor_in!, #powered_in!, #secretary_in!, #translate_errors
Instance Method Details
#create ⇒ Object
POST /categories
Create a new Category set @category as new Category with #category_params as param
49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/categories_controller.rb', line 49 def create @category = Category.new(category_params) if @category.save categories flash.now[:success] = 'Creazione avvenuta con successo' render :index, status: :ok else flash.now[:error] = 'Si è verificato un errore durante la creazione' render :new, status: :error end end |
#destroy ⇒ Object
DELETE /categories/1
destroy a category
-
#set_category has set @category for destroy
84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/categories_controller.rb', line 84 def destroy if @category.destroy flash.now[:success] = 'Cancellazione avvenuta con successo' else flash.now[:error] = 'Si è verificato un errore durante la cancellazione' end render turbo_stream: [ turbo_stream.replace(:flashes, partial: "flashes"), turbo_stream.remove("category_#{@category.id}") ] end |
#edit ⇒ Object
GET /categories/1/edit
Render the form for edit a category #set_category has set @category for edit
42 |
# File 'app/controllers/categories_controller.rb', line 42 def edit; end |
#index ⇒ Object
GET /categories
render categories index set @pagy, @categories for the categorie pagination
17 |
# File 'app/controllers/categories_controller.rb', line 17 def index; end |
#list ⇒ Object
GET /categories/list
render the list the all Audit
-
set @pagy, @categories for the @categories pagination
24 25 26 |
# File 'app/controllers/categories_controller.rb', line 24 def list @pagy, @categories = pagy(categories, link_extra: "data-turbo-frame='categories'") end |
#new ⇒ Object
GET /categories/new
Render the form for create a new category set @category as new Category
33 34 35 |
# File 'app/controllers/categories_controller.rb', line 33 def new @category = Category.new end |
#update ⇒ Object
PATCH/PUT /categories/1
update a category #set_category has set @category for update and update with #category_params as param
67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/categories_controller.rb', line 67 def update if @category.update(category_params) categories flash.now[:success] = 'Modifica avvenuta con successo' render :index, status: :ok else flash.now[:error] = 'Si è verificato un errore durante la modifica' render :edit, status: :error end end |