Class: Contai::GenerationsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/contai/generations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/contai/generations_controller.rb', line 3

def create
  model_class = params[:model].constantize
  record = model_class.find(params[:id])
  
  if record.generate_ai_content!
    render json: { 
      success: true, 
      content: record.send(record.class.contai_config[:output_field])
    }
  else
    render json: { 
      success: false, 
      errors: record.errors.full_messages 
    }, status: 422
  end
rescue => e
  render json: { 
    success: false, 
    error: e.message 
  }, status: 500
end