dawarich/app/controllers/visits_controller.rb

39 lines
943 B
Ruby
Raw Normal View History

2024-07-24 14:25:16 -04:00
# frozen_string_literal: true
class VisitsController < ApplicationController
before_action :authenticate_user!
2024-07-27 06:35:47 -04:00
before_action :set_visit, only: %i[update]
2024-07-24 14:25:16 -04:00
def index
order_by = params[:order_by] || 'asc'
2024-08-05 15:23:08 -04:00
status = params[:status] || 'confirmed'
2024-07-24 14:25:16 -04:00
visits = current_user
.visits
2024-08-05 15:23:08 -04:00
.where(status:)
2025-03-02 15:24:57 -05:00
.includes(%i[suggested_places area points])
.order(started_at: order_by)
2024-07-24 14:25:16 -04:00
2024-08-05 15:23:08 -04:00
@suggested_visits_count = current_user.visits.suggested.count
2024-12-11 08:21:44 -05:00
@visits = visits.page(params[:page]).per(10)
2024-07-24 14:25:16 -04:00
end
def update
if @visit.update(visit_params)
redirect_back(fallback_location: visits_path(status: :suggested))
2024-07-24 14:25:16 -04:00
else
render :edit, status: :unprocessable_entity
end
end
private
def set_visit
@visit = current_user.visits.find(params[:id])
end
def visit_params
params.require(:visit).permit(:name, :started_at, :ended_at, :status)
end
end