Class: MessagesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/appchat/templates/messages_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
# File 'lib/generators/appchat/templates/messages_controller.rb', line 8

def create
  @message = @chat.messages.build(message_params)
  if @message.save
    GetAiResponseJob.perform_later(@message.chat_id, @message.content)
    redirect_to new_message_path(chat_id: @chat.id), notice: 'Message was successfully created.'
  else
    render :new
  end
end

#indexObject



18
19
20
# File 'lib/generators/appchat/templates/messages_controller.rb', line 18

def index
  @messages = @chat.messages
end

#newObject



4
5
6
# File 'lib/generators/appchat/templates/messages_controller.rb', line 4

def new
  @message = @chat.messages.new
end