diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 25a39b1..3913646 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -153,4 +153,17 @@ th { gap: 0.3em; } +.field-error { + color: #dc3545; + font-size: 12px; + margin-top: 4px; + font-weight: 500; +} + +input.error, textarea.error { + width: 100%; + border-color: #dc3545; + box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25); +} + diff --git a/app/controllers/puzzles_controller.rb b/app/controllers/puzzles_controller.rb index 72380c5..8771524 100644 --- a/app/controllers/puzzles_controller.rb +++ b/app/controllers/puzzles_controller.rb @@ -16,15 +16,14 @@ def edit def update @puzzle = Puzzle.find(params[:id]) - if @puzzle.update(puzzle_params) - respond_to do |format| + + respond_to do |format| + if @puzzle.update(puzzle_params) format.turbo_stream format.html { redirect_to puzzles_path, notice: "Puzzle updated." } format.json { render json: { success: true, puzzle: @puzzle } } - end - else - respond_to do |format| - format.turbo_stream { render turbo_stream: turbo_stream.replace(@puzzle, partial: "puzzles/form", locals: { puzzle: @puzzle }) } + else + format.turbo_stream { render turbo_stream: turbo_stream.replace("modal", partial: "puzzles/edit_modal", locals: { puzzle: @puzzle }), status: :unprocessable_entity } format.html { render :edit, status: :unprocessable_entity } format.json { render json: { success: false, errors: @puzzle.errors.full_messages }, status: :unprocessable_entity } end diff --git a/app/models/puzzle.rb b/app/models/puzzle.rb index c7ee3f5..ebb5c64 100644 --- a/app/models/puzzle.rb +++ b/app/models/puzzle.rb @@ -3,5 +3,7 @@ class Puzzle < ApplicationRecord enum :state, { approved: 0, rejected: 1, pending: 2, archived: 3 } has_many :answers + validates :question, presence: true + scope :archived, -> { where(state: :archived).order(sent_at: :desc) } end diff --git a/app/views/puzzles/_edit_modal.html.erb b/app/views/puzzles/_edit_modal.html.erb new file mode 100644 index 0000000..6f33c7a --- /dev/null +++ b/app/views/puzzles/_edit_modal.html.erb @@ -0,0 +1,11 @@ + + + diff --git a/app/views/puzzles/_form.html.erb b/app/views/puzzles/_form.html.erb index a342f8c..8689dba 100644 --- a/app/views/puzzles/_form.html.erb +++ b/app/views/puzzles/_form.html.erb @@ -1,7 +1,10 @@ -<%=form_with model: @puzzle do |f| %> +<%= form_with model: puzzle do |f| %>