klaay-chatbot/app/controllers/conversations_controller.rb

33 lines
774 B
Ruby

# frozen_string_literal: true
class ConversationsController < ApplicationController
load_and_authorize_resource except: %i[create]
def index
@conversations = Conversation.accessible_by(current_ability)
end
def show
@messages = @conversation.messages
@prompt = Message.new(conversation: @conversation)
end
def create
# NOTE: Real application would have agent be given from params
@conversation = @current_user.conversations.new(agent: 'DummyAgent')
if @conversation.save
redirect_to @conversation
else
render :index, status: :unprocessable_entity
end
end
def destroy
if @conversation.destroy
redirect_to conversations_path
else
render :show, status: :unprocessable_entity
end
end
end