RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: Saidbek
Site: http://www.notes.kloop.kg
Mohamed Sami there're 2 ways to pass your issue
just use collect instead of each
collect
each
def load_imported_products spreadsheet = open_spreadsheet header = spreadsheet.row(1) (2..spreadsheet.last_row).collect do |i| row = Hash[[header, spreadsheet.row(i)].transpose] product = Product.find_by_id(row['id']) || Product.new product.attributes = row.to_hash.slice(*accessible_attributes) product end end
try adding each product to an array, then just return it
def load_imported_products spreadsheet = open_spreadsheet header = spreadsheet.row(1) products = [] (2..spreadsheet.last_row).collect do |i| row = Hash[[header, spreadsheet.row(i)].transpose] product = Product.find_by_id(row['id']) || Product.new product.attributes = row.to_hash.slice(*accessible_attributes) products << product end products end
Mohamed Sami there're 2 ways to pass your issue
just use
collect
instead ofeach
try adding each product to an array, then just return it