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!

有帮助吗?

解决方案

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:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top