I have to import personal files from the link from the website having a text file using Ruby.

I'm able to import the whole text right into a single variable (I did not include my specific link):

text = Net::HTTP.get( URI.parse( "http://www.link.com/text.txt" ) )

but I'm not sure how you can import line by line in to the database. I have to have the ability to see clearly as an array, such as this:

text.each do |line|
  Thing.create :variable => line
end

That code would save each line in to the database within the "things" table as "variable". If the were my text file:

abc
def
ghi
jkl

This is exactly what the table need to look as with the database:

things

id variable
1  abc
2  def
3  ghi
4  jkl

Once more, I have to understand how to import a text file from the website (not really a disk drive) to offer the above result. Thanks.

I'd split the information on newlines after which call each.


text = Internet::HTTP.get( URI.parse( "http://www.link.com/text.txt" ) )

text.split("n").each do

    ...

finish

I'd then make use of the Mysql2 jewel to place the values to your database.


db = Mysql2::Client.new(connection_params)

db.query(place_statement)