lukaszkups
lukaszkups

Reputation: 5990

save a text from text file through rails console

like in title - I want to save a content of a text file in database (and couple other things) through rails console - how to do it?

I'm entering rails console by: rails c and then I should do

`MyItem.create! body: content_from_my_text_file, field1: '123', field2: 'abc'

but how force rails console to read from file and write the content to the database? Is there any simple solution? Please help!

Upvotes: 1

Views: 1531

Answers (1)

luis.parravicini
luis.parravicini

Reputation: 1227

You don't need rails to read a file. You could get all the data of a file in a string with IO.read(path).

You should read more about it in:

Upvotes: 1

Related Questions