How to write contents of a rails database to external file
Posted
by
user1296787
on Stack Overflow
See other posts from Stack Overflow
or by user1296787
Published on 2012-03-27T23:19:29Z
Indexed on
2012/03/27
23:30 UTC
Read the original article
Hit count: 172
I'm trying to have rails send the contents of my database to an external textfile. I wanted this done everytime a new user is created.
However, when i try to do the following in my user.rb model file,
before_save :write_data
def write_data()
File.open("data.txt", "w") do |myfile|
myfile.write(User.all)
end
end
It doesn't write the actual contents of the database, instead, it displays something like this
User:0x109858540
Can anyone help? Thanks.
© Stack Overflow or respective owner