@@ -44,30 +44,13 @@ def create
4444 end
4545 end
4646
47- def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
47+ def update
4848 authorize @navigation_item
4949
50- respond_to do |format |
51- if @navigation_item . update ( navigation_item_params )
52- flash [ :notice ] = t ( 'navigation_item.updated' )
53- format . html { redirect_to @navigation_area , notice : t ( 'navigation_item.updated' ) }
54- format . turbo_stream do
55- redirect_to @navigation_area , only_path : true
56- end
57- else
58- flash . now [ :alert ] = t ( 'navigation_item.update_failed' )
59- format . html { render :edit , status : :unprocessable_entity }
60- format . turbo_stream do
61- render turbo_stream : [
62- turbo_stream . update ( 'form_errors' , partial : 'layouts/better_together/errors' ,
63- locals : { object : @navigation_item } ) ,
64- turbo_stream . update ( 'navigation_item_form' , partial : 'better_together/navigation_items/form' ,
65- # rubocop:todo Layout/LineLength
66- locals : { navigation_item : @navigation_item , navigation_area : @navigation_area } )
67- # rubocop:enable Layout/LineLength
68- ]
69- end
70- end
50+ if @navigation_item . update ( navigation_item_params )
51+ handle_update_success
52+ else
53+ handle_update_failure
7154 end
7255 end
7356
@@ -80,6 +63,30 @@ def destroy
8063
8164 private
8265
66+ def handle_update_success
67+ flash [ :notice ] = t ( 'navigation_item.updated' )
68+ respond_to do |format |
69+ format . html { redirect_to @navigation_area , notice : flash [ :notice ] }
70+ format . turbo_stream { redirect_to @navigation_area , only_path : true }
71+ end
72+ end
73+
74+ def handle_update_failure
75+ flash . now [ :alert ] = t ( 'navigation_item.update_failed' )
76+ respond_to do |format |
77+ format . html { render :edit , status : :unprocessable_entity }
78+ format . turbo_stream do
79+ render turbo_stream : [
80+ turbo_stream . update ( 'form_errors' , partial : 'layouts/better_together/errors' ,
81+ locals : { object : @navigation_item } ) ,
82+ turbo_stream . update ( 'navigation_item_form' , partial : 'better_together/navigation_items/form' ,
83+ locals : { navigation_item : @navigation_item ,
84+ navigation_area : @navigation_area } )
85+ ]
86+ end
87+ end
88+ end
89+
8390 def available_parent_items
8491 BetterTogether ::NavigationItem . where . not ( id : @navigation_item . id ) . includes (
8592 :string_translations ,
0 commit comments