Skip to content

Commit

Permalink
Merge pull request #56 from leouofa/add-edit-prompt-to-meta
Browse files Browse the repository at this point in the history
adding the ability to edit prompt to meta
  • Loading branch information
leouofa authored Oct 21, 2024
2 parents fda3ff0 + 54830ec commit 7bc2993
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
16 changes: 0 additions & 16 deletions app/controllers/characters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ def index
@component_list = @component_klass.send('where', where).send(scope).order(created_at: :asc).page params[:page]
end

def edit_prompt
set_component
end

def generate_prompt
set_component
GenerateCharacterPromptJob.perform_later(@component)
Expand All @@ -28,18 +24,6 @@ def iterate
end
end

def update
if @component.update(component_params)
if component_params[:prompt]
redirect_to send(@component_detail_path, @component.id), notice: "#{@component_name} was successfully updated."
else
redirect_to send(@component_list_path), notice: "#{@component_name} was successfully updated."
end
else
render component_params[:prompt] ? :edit_prompt : :edit
end
end

private

def component_name
Expand Down
12 changes: 9 additions & 3 deletions app/controllers/meta_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class MetaController < ApplicationController
include RestrictedAccess

before_action :set_meta
before_action :set_component, only: [:show, :edit, :update, :destroy]
before_action :set_component, only: [:show, :edit, :edit_prompt, :update, :destroy]
before_action :set_parent, only: [:index, :show, :new, :create, :edit, :update, :destroy]

def index
Expand All @@ -19,6 +19,8 @@ def edit; end

def show; end

def edit_prompt; end

def create
@component = @component_klass.new(component_params)
if @component.save
Expand All @@ -38,9 +40,13 @@ def destroy

def update
if @component.update(component_params)
redirect_to send(@component_list_path), notice: "#{@component_name} was successfully updated."
if component_params[:prompt]
redirect_to send(@component_detail_path, @component.id), notice: "#{@component_name} was successfully updated."
else
redirect_to send(@component_list_path), notice: "#{@component_name} was successfully updated."
end
else
render :edit
render component_params[:prompt] ? :edit_prompt : :edit
end
end

Expand Down

0 comments on commit 7bc2993

Please sign in to comment.