Now the aim was to extract all the information from the CSV (sound simple right ). Yes, it is but I resist the thought of putting the file in Amazon S3 server(first) and then downloading the file and to my server and then extract the data from the CSV file and dump it into the database. I want it to be more real time(since the file is small size file) I want the user to know that the data in CSV is proper or not and can or cannot data in the CSV can be dumped into database citing validations.
Yes I knew now I have to achieve something of this sort , but howWell, looking at the uploader file generated by CarrierWave I found out that there is process method, ok now what how do you apply it.
Inspecting the CarrierWave source code ( for default resize process ) I found out that all you need is to define a method wrapped inside a module .
Now it got it.
So to define a custom processing all you need is to define method wrapped in module and include that module in CarrierWave and pass your process method as an argument to CarrierWave process method define in uploader file
Here how I achieve this.
Inside CarrierWave Uploader
class AssetUploader < CarrierWave::Uploader::Base include CarrierWave::CSVProcessor process :process_csv end
That it that all you need to do to define your own file processing.
Just go ahead an define your process_csv method inside module define in file inside config/initializers Voila mission accomplished.
Here how I did it (my file config/initializers/csv_processor.rb)
module CarrierWave module CSVProcessor def process_csv .... .... .... end end end
Go hack now with CarrierWave.
By the way if you want to explore the thought of providing custom error message for CarrierWave here a link that you might want to look at
Hope that it help you in someway or other
Follow me on Twitter