0

I want to import data from a csv file into my database in rails. The model to which I want to import data is:

create_table "clubs", force: true do |t|
   t.text     "club"
   t.text     "location"
   t.text     "address"
   t.text     "description"
   t.string   "email"
   t.string   "phone"
   t.datetime "created_at"
   t.datetime "updated_at"
   t.string   "photo_file_name"
   t.string   "photo_content_type"
   t.integer  "photo_file_size"
   t.datetime "photo_updated_at"
   t.string   "city"
   t.float    "latitude"
   t.float    "longitude"
end

In the csv file I have data for 'club', 'location', 'address', 'email', 'phone' and 'city', but it is possible that for some rows the data of any of the above mentioned attributes might be missing.

So, can anyone help me how to migrate the data from this csv file in database using rake task?

Thanks in advance.

Lovish Choudhary
  • 167
  • 2
  • 17
  • Well, this could get you started: http://stackoverflow.com/questions/26212250/creating-rake-task-for-importing-data-from-csv-file. Just put an empty string to the field for anything that is nil? (if it's just blank?, but not nil?, that should be okay). – rdnewman Jul 22 '15 at 20:44
  • Come to think about, leaving them nil is probably okay if you want, but you'll have to deal with the missing data in the main logic of your application if you depend on them having values. – rdnewman Jul 22 '15 at 21:01

0 Answers0