Class: CompletionKit::PromptsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CompletionKit::PromptsController
- Defined in:
- app/controllers/completion_kit/prompts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #publish ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 22 def create @prompt = Prompt.new(prompt_params) if @prompt.save redirect_to prompt_path(@prompt), notice: "Prompt version was successfully created." else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
44 45 46 47 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 44 def destroy @prompt.destroy redirect_to prompts_path, notice: "Prompt version was successfully destroyed." end |
#edit ⇒ Object
19 20 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 19 def edit end |
#index ⇒ Object
5 6 7 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 5 def index @prompts = Prompt.current_versions.includes(:runs).order(created_at: :desc) end |
#new ⇒ Object
15 16 17 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 15 def new @prompt = Prompt.new end |
#publish ⇒ Object
49 50 51 52 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 49 def publish @prompt.publish! redirect_to prompt_path(@prompt), notice: "#{@prompt.display_name} is now the current version." end |
#show ⇒ Object
9 10 11 12 13 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 9 def show @runs = Run.where(prompt_id: @prompt.family_versions.select(:id)) .includes(:prompt, :dataset, responses: :reviews) .order(created_at: :desc) end |
#update ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 32 def update if @prompt.runs.exists? new_prompt = @prompt.clone_as_new_version(prompt_params.to_h) new_prompt.publish! redirect_to prompt_path(new_prompt), notice: "Saved as #{new_prompt.version_label}." elsif @prompt.update(prompt_params) redirect_to prompt_path(@prompt), notice: "Prompt saved." else render :edit, status: :unprocessable_entity end end |