Class: FaqsController

Inherits:
ApplicationController show all
Includes:
Pagy::Backend
Defined in:
app/controllers/faqs_controller.rb

Overview

This controller manage the views refering to Faq model

Instance Method Summary collapse

Instance Method Details

#createObject

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

#destroyObject

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

#editObject

GET /faqs/1/edit



31
# File 'app/controllers/faqs_controller.rb', line 31

def edit; end

#indexObject

GET /faqs or /faqs.json



12
# File 'app/controllers/faqs_controller.rb', line 12

def index; end

#listObject



14
15
16
# File 'app/controllers/faqs_controller.rb', line 14

def list
  faqs
end

#newObject

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

#showObject

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

#updateObject

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