I’m looking for a way to slurp or dump a table to a yml file.
I have found several ‘backup’ procedures but they cause problems with my
join tables and I just want to dump a couple of the join tables anyway.
Is there some easy way to do this?
Craig
I’m looking for a way to slurp or dump a table to a yml file.
I have found several ‘backup’ procedures but they cause problems with my
join tables and I just want to dump a couple of the join tables anyway.
Is there some easy way to do this?
Craig
I just tried this in script/console:
$ ./script/console
Loading development environment (Rails 2.0.2)
File.open “users.txt”, “w” do |file|
?> User.all.each do |user|
?> file.write user.to_yamlend
end
=> […bunch of users…]exit
$ ls
Capfile app/ data/ doc/ lib/ public/
spec/ test/ users.txt
Rakefile config/ db/ flex/ log/ script/
stories/ tmp/ vendor/
$
The file was created at the root of my rails app. I don’t know if
there are better ways to do it, but that was certainly quick.
Regards,
Craig
On Wed, 2008-05-28 at 14:32 -0400, Craig D. wrote:
exit
$ ls
Capfile app/ data/ doc/ lib/ public/
spec/ test/ users.txt
Rakefile config/ db/ flex/ log/ script/
stories/ tmp/ vendor/
$The file was created at the root of my rails app. I don’t know if
there are better ways to do it, but that was certainly quick.
gotcha…nice…thanks
Craig
On Wed, 2008-05-28 at 14:32 -0400, Craig D. wrote:
exit
$ ls
Capfile app/ data/ doc/ lib/ public/
spec/ test/ users.txt
Rakefile config/ db/ flex/ log/ script/
stories/ tmp/ vendor/
$The file was created at the root of my rails app. I don’t know if
there are better ways to do it, but that was certainly quick.
this works except for one thing…each record is written like this…
— !ruby/object:Right
attributes:
name: Personnel Admin
action: index
id: “1”
controller: assessments
— !ruby/object:Right
attributes:
name: Personnel Admin
action: find
id: “2”
controller: assessments
so each item has the same identifier and you cannot use it without
modification. I suppose I could figure out a way with sed but this
doesn’t quite work as well as I had hoped.
Thanks
Craig
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs