Skip to content

Commit

Permalink
Merge pull request #287 from 2525nicole/feature/create-error-messages…
Browse files Browse the repository at this point in the history
…-partial

Feature/create error messages partial
  • Loading branch information
2525nicole authored Oct 20, 2024
2 parents 1a835b6 + 9ecf56c commit 25d6365
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/helpers/memories_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def exclude_memory_from_page(memory_category_id, memory)
turbo_streams = [
turbo_stream.remove(memory),
turbo_stream.update("memories-count-#{memory_category_id}", partial: 'category_memories/memories-count', locals: { category: category.reload }),
turbo_stream.update('flash', partial: 'layouts/flash')
turbo_stream.update('flash', partial: 'shared/flash')
]

turbo_streams << turbo_stream.update('memories', partial: 'category_memories/no_category_memories_message') if memories_count.zero?
Expand Down Expand Up @@ -47,7 +47,7 @@ def add_memory_to_page(memory, category)
]
end

turbo_streams << turbo_stream.update('flash', partial: 'layouts/flash')
turbo_streams << turbo_stream.update('flash', partial: 'shared/flash')
render turbo_stream: turbo_streams
end

Expand Down
5 changes: 1 addition & 4 deletions app/views/categories/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
.absolute.-top-16.left-1/2.-translate-x-1/2.bg-white.rounded-md.w-full.sm:max-w-md.max-h-80vh.overflow-y-scroll data-action='click->modal#stay'
= render 'categories/category_description'
= form_with(model: category, class: 'w-full text-base', data: { controller: 'character-counter' }) do |form|
- if category.errors.any?
ul.flex.flex-col.items-center
- category.errors.full_messages.each do |message|
li.text-red-500.mb-2.block = message
= render 'shared/error_messages', errors: @category.errors.full_messages if @category.errors.any?
.w-full.max-w-2xl.mx-auto.justify-center
= form.text_field :name, id: 'category_name', placeholder: '例:嬉しかった出来事', class: 'w-full mx-auto text-lg rounded', data: { character_counter_target: 'input', action: 'input->character-counter#updateCounter', max_length: 15 }
.text-gray-500.mt-2.text-right
Expand Down
2 changes: 1 addition & 1 deletion app/views/categories/create.turbo_stream.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
= turbo_stream.remove 'no-categories-message'
= turbo_stream.prepend 'categories', @category
= turbo_stream.update 'flash', partial: 'layouts/flash'
= turbo_stream.update 'flash', partial: 'shared/flash'
2 changes: 1 addition & 1 deletion app/views/categories/destroy.turbo_stream.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= turbo_stream.remove @category
= turbo_stream.update 'flash', partial: 'layouts/flash'
= turbo_stream.update 'flash', partial: 'shared/flash'
- if @category_count&.zero?
= turbo_stream.update 'categories', partial: 'no_categories_message'
2 changes: 1 addition & 1 deletion app/views/categories/update.turbo_stream.slim
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
= turbo_stream.replace @category
= turbo_stream.update 'flash', partial: 'layouts/flash'
= turbo_stream.update 'flash', partial: 'shared/flash'
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ html.bg-slate-200

main.container.flex-grow[class=container_padding_class]
#flash
= render 'layouts/flash'
= render 'shared/flash'
= yield

- if user_signed_in? && (current_page?(authenticated_root_path) || current_page?(memories_path) || (params[:category_id].present? && current_page?(category_memories_path(category_id: params[:category_id]))))
Expand Down
10 changes: 2 additions & 8 deletions app/views/memories/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
- placeholder_text = "例:一時帰国中の●●と会った。\n相変わらず元気でパワフルで、たくさんの刺激をもらった!目標に向かって頑張る人はかっこいい!\n私も何かチャレンジしたい気持ちになった。キックボクシングの体験教室行ってみようかな〜"
= form_with(model: memory, class: 'w-full', data: { controller: 'character-counter' }) do |form|
- if @memory.errors.any?
ul.flex.flex-col.items-center
- @memory.errors.full_messages.each do |message|
li.text-red-500.font-normal.text-sm.sm:text-base.mb-2.block = message
- if @category_errors.any?
ul.flex.flex-col.items-center
- @category_errors.each do |message|
li.text-red-500.font-normal.text-sm.sm:text-base.mb-2.block = message
= render 'shared/error_messages', errors: @memory.errors.full_messages if @memory.errors.any?
= render 'shared/error_messages', errors: @category_errors if @category_errors.any?
.sm:px-6
.flex.flex-col.w-full.mx-auto.mb-4.sm:mb-6.text-center.gap-2
h2.text-base.sm:text-lg
Expand Down
2 changes: 1 addition & 1 deletion app/views/memories/create.turbo_stream.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
= turbo_stream.prepend 'memories', @memory
= turbo_stream.remove 'no-memories-message'
= turbo_stream.update 'flash', partial: 'layouts/flash'
= turbo_stream.update 'flash', partial: 'shared/flash'
2 changes: 1 addition & 1 deletion app/views/memories/destroy.turbo_stream.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= turbo_stream.remove @memory
= turbo_stream.update 'flash', partial: 'layouts/flash'
= turbo_stream.update 'flash', partial: 'shared/flash'
- if @memories_count&.zero?
= turbo_stream.update 'memories', partial: 'no_memories_message'
2 changes: 1 addition & 1 deletion app/views/memories/update.turbo_stream.slim
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
= turbo_stream.replace @memory
= turbo_stream.update 'flash', partial: 'layouts/flash'
= turbo_stream.update 'flash', partial: 'shared/flash'
4 changes: 4 additions & 0 deletions app/views/shared/_error_messages.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- if errors.any?
ul.flex.flex-col.items-center
- errors.each do |message|
li.text-red-500.font-normal.text-sm.sm:text-base.mb-2.block = message
File renamed without changes.

0 comments on commit 25d6365

Please sign in to comment.