/
Dmitry-F
/
cbt_tool
Обзор
Документация
Войти
/
Dmitry-F
/
cbt_tool
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
app/controllers/clients_controller.rb.bak
63 строки
2 KB
Dmitriy-Filatov
🎯 ФАЗА 2: Дашборд и интеграция движка SmerDiary
12 мар 2026, 18:04
12 мар 2026, 18:04
5d71337
Код
Авторство
О чём код?
class ClientsController < ApplicationController before_action :require_login before_action :set_client, only: %i[show edit update destroy] def index @clients = current_therapist.clients end def new @client = current_therapist.clients.build end def create @client = current_therapist.clients.build(client_params) if @client.save redirect_to clients_path, notice: "Клиент успешно создан" else render :new, status: :unprocessable_entity end end def show; end def edit; end def update if @client.update(client_params) redirect_to client_path(@client), notice: "Данные обновлены" else render :edit, status: :unprocessable_entity end end def destroy @client.destroy redirect_to clients_path, notice: "Клиент удалён", status: :see_other end def search term = params[:query].to_s.strip if term.present? @clients = current_therapist.clients.where( "name ILIKE :q OR email ILIKE :q OR phone ILIKE :q", q: "%#{term}%" ) else @clients = current_therapist.clients end render partial: "clients/list", layout: false, locals: { clients: @clients } end private def set_client @client = current_therapist.clients.find(params[:id]) rescue ActiveRecord::RecordNotFound redirect_to clients_path, alert: "Клиент не найден" end def client_params params.require(:client).permit(:name, :email, :phone, :notes) end end