Class: CompletionKit::PromptsController
Constant Summary
ApplicationController::ONBOARDING_DISMISS_COOKIE
Instance Method Summary
collapse
Instance Method Details
#create ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/completion_kit/prompts_controller.rb', line 24
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
47
48
49
50
|
# File 'app/controllers/completion_kit/prompts_controller.rb', line 47
def destroy
@prompt.destroy
redirect_to prompts_path, notice: "Prompt version was successfully destroyed."
end
|
#edit ⇒ Object
21
22
|
# File 'app/controllers/completion_kit/prompts_controller.rb', line 21
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
17
18
19
|
# File 'app/controllers/completion_kit/prompts_controller.rb', line 17
def new
@prompt = Prompt.new
end
|
#publish ⇒ Object
52
53
54
55
|
# File 'app/controllers/completion_kit/prompts_controller.rb', line 52
def publish
@prompt.publish!
redirect_to prompt_path(@prompt), notice: "#{@prompt.display_name} is now the published version."
end
|
#show ⇒ Object
10
11
12
13
14
15
|
# 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)
.display_scoped
end
|
#update ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/completion_kit/prompts_controller.rb', line 34
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
|