Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[lacks tests] Bugfix Edition Revised #7

Merged
merged 2 commits into from

2 participants

@jumph4x

No description provided.

jumph4x added some commits
@jumph4x jumph4x Bugfix 0fb9591
@jumph4x jumph4x Fixing as per @minustehbare's review remark; avoiding index shifting …
…left.

keeping a nil value in place keeps headers[] and row[] aligned
c7ff115
@minustehbare minustehbare merged commit d0ac06a into minustehbare:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 13, 2011
  1. @jumph4x

    Bugfix

    jumph4x authored
  2. @jumph4x

    Fixing as per @minustehbare's review remark; avoiding index shifting …

    jumph4x authored
    …left.
    
    keeping a nil value in place keeps headers[] and row[] aligned
This page is out of date. Refresh to see the latest.
View
2  app/controllers/admin/product_datasheets_controller.rb
@@ -27,7 +27,7 @@ def destroy
else
@product_datasheet.errors.add_to_base('Failed to delete the product datasheet')
end
- redirect_to admin_product_datasheets_path
+ redirect_to admin_product_datasheets_path(:format => :html)
end
def clone
View
10 app/models/product_datasheet.rb
@@ -38,6 +38,14 @@ def perform
columns = [worksheet.dimensions[2], worksheet.dimensions[3]]
headers = worksheet.row(0)
+ headers.collect! do |key|
+ if Product.column_names.include?(key) or Variant.column_names.include?(key)
+ key
+ else
+ nil
+ end
+ end
+
####################
# Creating Variants:
# 1) First cell of headers row must define 'id' as the search key
@@ -57,7 +65,7 @@ def perform
worksheet.each(1) do |row|
attr_hash = {}
for i in columns[0]..columns[1]
- attr_hash[headers[i]] = row[i] unless row[i].nil?
+ attr_hash[headers[i]] = row[i] if row[i] and headers[i] # if there is a value and a key
end
if headers[0] == 'id' and row[0].nil? and headers.include? 'product_id'
create_variant(attr_hash)
Something went wrong with that request. Please try again.