Skip to content

Commit

Permalink
Output debugging information to help investigate bogus changes to the…
Browse files Browse the repository at this point in the history
… sells field through the enterprises bulk edit action
  • Loading branch information
RohanM committed Mar 18, 2015
1 parent cf4ccc2 commit ab9bc7b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/controllers/admin/enterprises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class EnterprisesController < ResourceController


helper 'spree/products'
include ActionView::Helpers::TextHelper
include OrderCyclesHelper

def for_order_cycle
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/enterprises/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab9bc7b

Please sign in to comment.