Class: HappeningsController

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

Overview

this controller manage the Happening model. this model is under FactsController

Instance Method Summary collapse

Methods inherited from ApplicationController

#access_denied!, #record_not_found!

Instance Method Details

#filter_paramssObject (private)

filter params for search Happening


44
45
46
# File 'app/controllers/happenings_controller.rb', line 44

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

#filter_ticketObject (private)

filter params for Happening's Ticket


49
50
51
# File 'app/controllers/happenings_controller.rb', line 49

def filter_ticket
  params.fetch(:ticket, {}).permit(:seats)
end

#indexObject

GET /fact/:fact_id/happenings show a paginate list of Happening


13
14
15
16
17
18
19
20
# File 'app/controllers/happenings_controller.rb', line 13

def index
  type = filter_paramss[:type] == 'history' ? 'history' : 'future'
  @text = ['detail ilike :text', { text: "%#{filter_paramss[:text]}%" }] if filter_paramss[:text].present?
  @pagy, @happenings = pagy(
    @fact.happenings.send(type).where(@text),
    items: 6
  )
end

#set_factObject (private)

set @fact for any action


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

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

#set_happeningObject (private)

set @happening when needed


34
35
36
# File 'app/controllers/happenings_controller.rb', line 34

def set_happening
  @happening = @fact.happenings.find(params[:id])
end

#set_ticketObject (private)

seet @ticket when needed


39
40
41
# File 'app/controllers/happenings_controller.rb', line 39

def set_ticket
  @ticket = @happening.tickets.find_or_initialize_by(user: current_user)
end

#showObject

GET /fact/:fact_id/happenings/:id Show detail of happening and a form to prenotate a ticket


24
# File 'app/controllers/happenings_controller.rb', line 24

def show; end