Class: CompletionKit::PromptsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CompletionKit::PromptsController
- Includes:
- TagFiltering
- 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
23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 23 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
46 47 48 49 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 46 def destroy @prompt.destroy redirect_to prompts_path, notice: "Prompt version was successfully destroyed." end |
#edit ⇒ Object
20 21 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 20 def edit end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 6 def index @prompts = apply_tag_filter(Prompt.current_versions.includes(:runs, :tags).order(created_at: :desc)) end |
#new ⇒ Object
16 17 18 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 16 def new @prompt = Prompt.new end |
#publish ⇒ Object
51 52 53 54 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 51 def publish @prompt.publish! redirect_to prompt_path(@prompt), notice: "#{@prompt.display_name} is now the current version." end |
#show ⇒ Object
10 11 12 13 14 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 10 def show @runs = Run.where(prompt_id: @prompt.family_versions.select(:id)) .includes(:prompt, :dataset, responses: :reviews) .order(created_at: :desc) end |
#update ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/completion_kit/prompts_controller.rb', line 33 def update if @prompt.runs.exists? new_prompt = @prompt.clone_as_new_version(prompt_params.except(:tag_names).to_h) new_prompt.publish! new_prompt.update!(tag_names: prompt_params[:tag_names]) if prompt_params.key?(:tag_names) 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 |