diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 37cf4ff09af..94522da36f7 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -14,6 +14,7 @@ class EnterprisesController < ResourceController helper 'spree/products' + include ActionView::Helpers::TextHelper include OrderCyclesHelper def for_order_cycle @@ -47,12 +48,20 @@ def set_sells def bulk_update @enterprise_set = EnterpriseSet.new(collection, params[:enterprise_set]) + touched_enterprises = @enterprise_set.collection.select(&:changed?) if @enterprise_set.save - flash[:success] = 'Enterprises updated successfully' + flash[:success] = "Enterprises updated successfully" + + # 18-3-2015: It seems that the form for this action sometimes loads bogus values for + # the 'sells' field, and submitting that form results in a bunch of enterprises with + # values that have mysteriously changed. This statement is here to help debug that + # issue, and should be removed (along with its display in index.html.haml) when the + # issue has been resolved. + flash[:action] = "Updated #{pluralize(touched_enterprises.count, 'enterprise')}: #{touched_enterprises.map(&:name).join(', ')}" + redirect_to main_app.admin_enterprises_path else - touched_ids = params[:enterprise_set][:collection_attributes].values.map { |v| v[:id].to_i } - @enterprise_set.collection.select! { |e| touched_ids.include? e.id } + @enterprise_set.collection.select! { |e| touched_enterprises.include? e } flash[:error] = 'Update failed' render :index end diff --git a/app/views/admin/enterprises/index.html.haml b/app/views/admin/enterprises/index.html.haml index 64b8423baaa..8269cd36991 100644 --- a/app/views/admin/enterprises/index.html.haml +++ b/app/views/admin/enterprises/index.html.haml @@ -10,6 +10,10 @@ = render :partial => 'spree/shared/error_messages', :locals => { :target => @enterprise_set } +-# For purposes of debugging bulk_update. See Admin/Enterprises#bulk_update. +- if flash[:action] + %p= flash[:action] + = form_for @enterprise_set, url: main_app.bulk_update_admin_enterprises_path do |f| %table#listing_enterprises.index %colgroup