Answer the question
In order to leave comments, you need to log in
How to pull out the price element from the row and remove all spaces between the numbers?
I'm trying to do a simple import of price from csv, but the prices in the file are in this format "4000". Rails trims zeros when stored in price:integer if there is a space before between 4 and 000. It turns out just "4".
Source:
def self.import(file)
CSV.foreach(file.path, :quote_char => "|", headers: true, :col_sep => "\t") do |row|
product = find_by_ones(row["ones"]) || new #ищу строку, значение ones
product.attributes = row.to_hash.except("title")
product.save!
end
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question