2022-04-29 18:29:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-05-30 19:45:51 +08:00
|
|
|
module StepElements
|
2022-05-25 20:23:35 +08:00
|
|
|
class TextsController < BaseController
|
|
|
|
before_action :load_step_text, only: %i(update destroy)
|
|
|
|
|
|
|
|
def create
|
|
|
|
step_text = @step.step_texts.build
|
|
|
|
create_in_step!(@step, step_text)
|
|
|
|
render_step_orderable_element(step_text)
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
head :unprocessable_entity
|
|
|
|
end
|
2022-04-29 18:29:42 +08:00
|
|
|
|
2022-05-25 20:23:35 +08:00
|
|
|
def update
|
|
|
|
@step_text.update!(step_text_params)
|
|
|
|
TinyMceAsset.update_images(@step_text, params[:tiny_mce_images], current_user)
|
|
|
|
render json: @step_text, serializer: StepTextSerializer
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
head :unprocessable_entity
|
2022-04-29 18:29:42 +08:00
|
|
|
end
|
|
|
|
|
2022-05-25 20:23:35 +08:00
|
|
|
def destroy
|
|
|
|
if @step_text.destroy
|
|
|
|
head :ok
|
|
|
|
else
|
|
|
|
head :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def step_text_params
|
2022-04-29 18:29:42 +08:00
|
|
|
params.require(:step_text).permit(:text)
|
|
|
|
end
|
2022-05-03 21:15:49 +08:00
|
|
|
|
2022-05-25 20:23:35 +08:00
|
|
|
def load_step_text
|
|
|
|
@step_text = @step.step_texts.find_by(id: params[:id])
|
|
|
|
return render_404 unless @step_text
|
2022-05-03 21:15:49 +08:00
|
|
|
end
|
2022-04-29 18:29:42 +08:00
|
|
|
end
|
|
|
|
end
|