I'm using Rails 3.0.3 and have data for my "categories" table already in the database, but want to create a seed file from it. Is there any rake task that will generate the seeds.rb format for me from this table?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
-
undefined method `type_cast' for #
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Rspec controller error expecting <“index”> but
Not sure about any existing rake tasks, but you can try running something like this in the rails console & paste the results into your seeds.rb file
(warning: dirty & untested)
Adjust for any additional fields you may have.
Hope this helps.
Old question, I have a new one based on @Brian's answer.
If you want to keep the entire row as is:
If you want to only write some attributes, change the write line to the following:
Or, if you wish all the attributes except some, for example timestamps:
There is a gem called
seed_dump
, which will do exactly what you want:I've used YamlDb to dump data from my development db and then load it up to another server. It dumps the data to a Yaml file, which will be used any time you want to use db:load to push it up to any other db server.
https://github.com/ludicast/yaml_db