Class: Layered::Assistant::ConversationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Layered::Assistant::ConversationsController
- Includes:
- StoppableResponse
- Defined in:
- app/controllers/layered/assistant/conversations_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from StoppableResponse
Instance Method Details
#create ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 32 def create @conversation = Conversation.new(conversation_params) @conversation.owner = l_ui_current_user @conversation.assistant = scoped(Assistant).find(conversation_params[:assistant_id]) if conversation_params[:assistant_id].present? @conversation.name = Conversation.default_name if @conversation.name.blank? if @conversation.save redirect_to layered_assistant.conversation_path(@conversation), notice: "Conversation was successfully created." else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
56 57 58 59 |
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 56 def destroy @conversation.destroy redirect_to layered_assistant.conversations_path, notice: "Conversation was successfully deleted." end |
#edit ⇒ Object
44 45 46 |
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 44 def edit @page_title = "Edit conversation" end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 9 def index if params[:assistant_id] @assistant = scoped(Assistant).find(params[:assistant_id]) @page_title = "Conversations - #{@assistant.name}" @pagy, @conversations = pagy(@assistant.conversations.merge(scoped(Conversation)).includes(:owner).by_created_at) else @page_title = "Conversations" @pagy, @conversations = pagy(scoped(Conversation).includes(:assistant, :owner).by_created_at) end end |
#new ⇒ Object
27 28 29 30 |
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 27 def new @page_title = "New conversation" @conversation = Conversation.new(params.permit(conversation: [:assistant_id])[:conversation]) end |
#show ⇒ Object
20 21 22 23 24 25 |
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 20 def show @page_title = @conversation.name @messages = @conversation..includes(:model).by_created_at @models = Model.available @selected_model_id = @messages.last&.model_id || @conversation.assistant.default_model_id || @models.first&.id end |
#update ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/controllers/layered/assistant/conversations_controller.rb', line 48 def update if @conversation.update(conversation_params) redirect_to layered_assistant.conversations_path, notice: "Conversation was successfully updated." else render :edit, status: :unprocessable_entity end end |