Class: FaqsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- FaqsController
- Includes:
- Pagy::Backend
- Defined in:
- app/controllers/faqs_controller.rb
Overview
This controller manage the views refering to Faq model
Instance Method Summary collapse
-
#create ⇒ Object
POST /faqs or /faqs.json.
-
#destroy ⇒ Object
DELETE /faqs/1 or /faqs/1.json.
-
#edit ⇒ Object
GET /faqs/1/edit.
-
#index ⇒ Object
GET /faqs or /faqs.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /faqs/new.
-
#show ⇒ Object
GET /faqs/1 or /faqs/1.json.
-
#update ⇒ Object
PATCH/PUT /faqs/1 or /faqs/1.json.
Instance Method Details
#create ⇒ Object
POST /faqs or /faqs.json
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/faqs_controller.rb', line 34 def create @faq = Faq.new(faq_params) if @faq.save render turbo_stream: [ turbo_stream.replace(:flashes, partial: "flashes"), turbo_stream.update(:yield, partial: "faqs/index") ] else flash.now[:error] = write_errors(@faq) render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") end end |
#destroy ⇒ Object
DELETE /faqs/1 or /faqs/1.json
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/faqs_controller.rb', line 59 def destroy if @faq.destroy flash.now[:success] = 'Cancellazione avvenuta con successo' render turbo_stream: [ turbo_stream.remove("faq_#{@faq.id}"), turbo_stream.replace(:flashes, partial: "flashes") ] else flash.now[:error] = write_errors(@faq) render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") end end |
#edit ⇒ Object
GET /faqs/1/edit
31 |
# File 'app/controllers/faqs_controller.rb', line 31 def edit; end |
#index ⇒ Object
GET /faqs or /faqs.json
12 |
# File 'app/controllers/faqs_controller.rb', line 12 def index; end |
#list ⇒ Object
14 15 16 |
# File 'app/controllers/faqs_controller.rb', line 14 def list faqs end |
#new ⇒ Object
GET /faqs/new
25 26 27 28 |
# File 'app/controllers/faqs_controller.rb', line 25 def new @faq = Faq.new @sample = Faq.accessible_by(current_ability).find(Faq.accessible_by(current_ability).pluck(:id).sample) end |
#show ⇒ Object
GET /faqs/1 or /faqs/1.json
19 20 21 22 |
# File 'app/controllers/faqs_controller.rb', line 19 def show @view = params[:view] || '' @current_ability.cannot(:manage, @faq) if @view == 'modal' end |
#update ⇒ Object
PATCH/PUT /faqs/1 or /faqs/1.json
49 50 51 52 53 54 55 56 |
# File 'app/controllers/faqs_controller.rb', line 49 def update if @faq.update(faq_params) flash.now[:success] = 'Modifica avvenuta con successo' else flash.now[:error] = write_errors(@faq) end render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") end |