Class: LlmLogs::PromptsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- LlmLogs::PromptsController
- Defined in:
- app/controllers/llm_logs/prompts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/llm_logs/prompts_controller.rb', line 22 def create @prompt = Prompt.new(prompt_params) if @prompt.save if version_params[:messages].present? @prompt.update_content!(**version_params) end redirect_to prompt_path(@prompt), notice: "Prompt created." else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
53 54 55 56 57 |
# File 'app/controllers/llm_logs/prompts_controller.rb', line 53 def destroy @prompt = Prompt.find(params[:id]) @prompt.destroy redirect_to prompts_path, notice: "Prompt deleted." end |
#edit ⇒ Object
35 36 37 38 |
# File 'app/controllers/llm_logs/prompts_controller.rb', line 35 def edit @prompt = Prompt.find(params[:id]) @current_version = @prompt.current_version end |
#index ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'app/controllers/llm_logs/prompts_controller.rb', line 3 def index tag = params[:tag].is_a?(String) ? params[:tag].presence : nil scope = Prompt.order(:name).includes(:versions) scope = scope.with_tag(tag) if tag @prompts = scope.page(params[:page]).per(25) @active_tag = tag @all_tags = Prompt.pluck(:tags).flatten.compact.uniq.sort end |
#new ⇒ Object
18 19 20 |
# File 'app/controllers/llm_logs/prompts_controller.rb', line 18 def new @prompt = Prompt.new end |
#show ⇒ Object
12 13 14 15 16 |
# File 'app/controllers/llm_logs/prompts_controller.rb', line 12 def show @prompt = Prompt.find(params[:id]) @current_version = @prompt.current_version @versions = @prompt.versions.order(version_number: :desc).limit(5) end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/llm_logs/prompts_controller.rb', line 40 def update @prompt = Prompt.find(params[:id]) if @prompt.update(prompt_params) if version_params[:messages].present? @prompt.update_content!(**version_params) end redirect_to prompt_path(@prompt), notice: "Prompt updated." else render :edit, status: :unprocessable_entity end end |