diff --git a/app/helpers/support_form_helper.rb b/app/helpers/support_form_helper.rb index 96650bae..aa61b7d1 100644 --- a/app/helpers/support_form_helper.rb +++ b/app/helpers/support_form_helper.rb @@ -3,6 +3,21 @@ module SupportFormHelper attr_reader :template delegate :concat, :content_tag, :image_tag, to: :template, private: true + def errors + return nil if object.errors.empty? + + error_list = content_tag(:ul) do + object.errors.each do |error| + concat content_tag(:li, error.full_message) + end + end + + content_tag(:p) do + concat "Could not save:" + concat error_list + end + end + def fields(&block) content_tag(:ul, class: "fields", &block) end diff --git a/app/views/alt_styles/edit.html.haml b/app/views/alt_styles/edit.html.haml index 8d15ac50..0dfe4f3d 100644 --- a/app/views/alt_styles/edit.html.haml +++ b/app/views/alt_styles/edit.html.haml @@ -14,12 +14,7 @@ = image_tag @alt_style.preview_image_url, class: "alt-style-preview" = support_form_with model: @alt_style, class: "support-form" do |f| - - if @alt_style.errors.any? - %p - Could not save: - %ul.errors - - @alt_style.errors.each do |error| - %li= error.full_message + = f.errors = f.fields do = f.field do diff --git a/app/views/items/edit.html.haml b/app/views/items/edit.html.haml index e748ce06..34fceb1e 100644 --- a/app/views/items/edit.html.haml +++ b/app/views/items/edit.html.haml @@ -9,12 +9,7 @@ it will probably be reverted automatically when someone models it. = support_form_with model: @item, class: "support-form" do |f| - - if @item.errors.any? - %p - Could not save: - %ul.errors - - @item.errors.each do |error| - %li= error.full_message + = f.errors = f.fields do = f.field do diff --git a/app/views/pet_states/edit.html.haml b/app/views/pet_states/edit.html.haml index 6caee0cd..01d6473a 100644 --- a/app/views/pet_states/edit.html.haml +++ b/app/views/pet_states/edit.html.haml @@ -18,12 +18,7 @@ = outfit_viewer pet_state: @pet_state = support_form_with model: [@pet_type, @pet_state] do |f| - - if @pet_state.errors.any? - %p - Could not save: - %ul.errors - - @pet_state.errors.each do |error| - %li= error.full_message + = f.errors = f.fields do = f.radio_grid_fieldset "Pose" do