Forum: Ruby on Rails YAML - How to load data directly

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
etienne.durand (Guest)
on 2005-11-26 12:52
(Received via mailing list)
Hi,

I would like to fill up a development database with some data (YAML
files). YAML is ready, but I don't have any clue to load them into AR
objects, and persist them to the database (files are utf-8).
Any help?

Jean-Etienne
brucebalmer (Guest)
on 2005-11-26 14:25
(Received via mailing list)
Jean-Etienne:

I may have missed your point, but in case I didn't and this saves you
some time.

Open terminal and type something like this:

mysql - u root -p<<password goes here>> <<database_name>> goes here
<   <<path_tp_yaml_file_goes_here>>

bruce
listbox (Guest)
on 2005-11-26 16:33
(Received via mailing list)
On 26-nov-2005, at 13:24, Bruce B. wrote:

> Jean-Etienne:
>
> I may have missed your point, but in case I didn't and this saves
> you some time.
>
> Open terminal and type something like this:
>
> mysql - u root -p<<password goes here>> <<database_name>> goes
> here   <   <<path_tp_yaml_file_goes_here>>

Since when MySQL directly supports YAML dumps, may I ask?

--
Julian 'Julik' Tarkhanov
me at julik.nl
Sebastian D. (Guest)
on 2005-11-26 17:26
(Received via mailing list)
If you want to load your test fixtures to the development database,
just run "rake load_fixtures".

If you want to have separate fixtures for dev and test, put your dev
fixtures in another directory (say, "db/fixtures") and copy this to
lib/tasks/fixtures.rake or your Rakefile:

desc "Load fixtures into the current environment's database"
task :load_dev_fixtures => :environment do
   require 'active_record/fixtures'
   ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
   Dir.glob(File.join(RAILS_ROOT, 'db', 'fixtures', '*.yml')).each do
|fixture_file|
     Fixtures.create_fixtures('db/fixtures', File.basename
(fixture_file, '.*'))
   end
end

Which is just a copy of the original load_fixtures tasks from rails/
railties/lib/tasks/database.rake with the paths changed.
This topic is locked and can not be replied to.