Class: TicketsController

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

Overview

this controller manage Ticket model

Instance Method Summary collapse

Methods inherited from ApplicationController

#default_url_options, #new_session_path

Instance Method Details

#createObject

POST /event/:event_id/happenings/:happening_id/tickets



24
25
26
27
28
# File 'app/controllers/tickets_controller.rb', line 24

def create
  @ticket = current_user.tickets.create(ticket_params)
  @happening = @ticket.happening
  @event = @happening.event
end

#destroyObject

POST /event/:event_id/happenings/:happening_id/tickets/:id



31
32
33
34
35
36
37
# File 'app/controllers/tickets_controller.rb', line 31

def destroy
  @ticket.destroy
  respond_to do |format|
    format.html { redirect_to tickets_path, notice: "Ticket was successfully destroyed." }
    format.turbo_stream
  end
end

#indexObject

GET /tickets



8
9
10
11
12
13
14
15
# File 'app/controllers/tickets_controller.rb', line 8

def index
  @scope = filter_params[:scope]
  search = { user: current_user }
  search[:happening] = { start_at: ((filter_params[:from].try(:to_date) || Date.today)..filter_params[:to].try(:to_date).try(:end_of_day)) }
  search[:happening_id] = @scope if @scope.present?
  @text = [ "events.title ilike :text", { text: "%#{filter_params[:text]}%" } ] if filter_params[:text].present?
  @pagy, @tickets = pagy Ticket.includes(happening: [ :event ], answers: [ :question ]).where(search).where(@text), items: 10
end

#newObject



17
18
19
20
21
# File 'app/controllers/tickets_controller.rb', line 17

def new
  @happening = Happening.find ticket_params[:happening_id]
  @answers = @happening.questions.map { |e| { question_id: e.id } }
  @ticket = Ticket.new happening: @happening, user: current_user, answers_attributes: @answers
end