Ruby on Rails

How to import CSV files in Ruby on Rails

Today we are going to learn how to upload data from a CSV file. We can imagine countries like we have CSV file where exist all countries or some of the countries then how to import these into our database “countries” table.

At first in the model, as like country.rb and we have two columns for a country which is name and code see the below

now we can add some functionalities in our countries controller

now final touch in our new.html.erb I mean CSV upload form

here we go!

Happy coding!


Sample CSV countries

Fool Dev

I didn't get trained by the school system like other kids, and when I did concentrate on learning, my mind was cluttered and locked by the programming of the system. © Huey Newton