I'm saving records into CSV using after_save_filer. I don't receive any error and also I can't find file, what was generated(if it exists).
Here is code what I'm using:
after_save :to_csv
def to_csv(options = {})
require 'csv'
CSV.open("C:/project/myfile.csv", "w") do |csv|
csv << self.class.column_names
csv << self.attributes.values_at(*column_names)
end
end
How can I check is after save filter has been run ? How I can set the path ?
To check if the after_save was run you can either put a debugger
statement inside the to_csv method and see if it stops there when you save the model, or you could simply put a puts "I am in to_csv method
inside the method and look for it in the console.