Hi, this blog is no longer maintained, my new blog is here

Ruby On Rails and a Conning Israeli entrepreneur

Dump a Model table to fixtures

 


def self.to_fixture
write_file(File.expand_path("test/fixtures/#{table_name}.yml", RAILS_ROOT),
self.find(:all).inject("---\n") { |s, record|
self.columns.inject(s+"#{record.id}:\n") { |s, c|
s+" #{{c.name => record.attributes[c.name]}.to_yaml[5..-1]}\n" }
})
end

0 comments:


The Web Ask eizesus.com

Subscribe

    follow me on Twitter

    Twiters Around

    About Me

    My photo
    I am a web developer for more than 9 years, managed, cried, coded, designed and made money in this industry. now trying to do it again.

    Labels