Class: FactsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/facts_controller.rb

Overview

This controller manage the Fact model

Instance Method Summary collapse

Methods inherited from ApplicationController

#access_denied!, #record_not_found!

Instance Method Details

#filter_paramsObject (private)

Filter params for facts search


29
30
31
# File 'app/controllers/facts_controller.rb', line 29

def filter_params
  params.fetch(:filter, {}).permit(:text, :type)
end

#indexObject

GET /facts


9
# File 'app/controllers/facts_controller.rb', line 9

def index; end

#listObject

GET /facts/list


15
16
17
18
19
# File 'app/controllers/facts_controller.rb', line 15

def list
  type = filter_params[:type] == 'history' ? 'history' : 'future'
  @text = ['title ilike :text', { text: "%#{filter_params[:text]}%" }] if filter_params[:text].present?
  @pagy, @facts = pagy(Fact.send(type).where(@text))
end

#set_factObject (private)

set fact when is needed


24
25
26
# File 'app/controllers/facts_controller.rb', line 24

def set_fact
  @fact = Fact.find(params[:id])
end

#showObject

GET /facts/:id


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

def show; end