Method: SeedFu::ActiveRecordExtension#seed
- Defined in:
- lib/seed-fu/active_record_extension.rb
#seed(*args, &block) ⇒ Object
Load some seed data. There are two ways to do this.
Verbose syntax
This will seed a single record. The ‘:id` parameter ensures that if a record already exists in the database with the same id, then it will be updated with the name and age, rather than created from scratch.
Person.seed(:id) do |s|
s.id = 1
s.name = "Jon"
s.age = 21
end
Note that ‘:id` is the default attribute used to identify a seed, so it need not be specified.
Terse syntax
This is a more succinct way to load multiple records. Note that both ‘:x` and `:y` are being used to identify a seed here.
Point.seed(:x, :y,
{ :x => 3, :y => 10, :name => "Home" },
{ :x => 5, :y => 9, :name => "Office" }
)
31 32 33 |
# File 'lib/seed-fu/active_record_extension.rb', line 31 def seed(*args, &block) SeedFu::Seeder.new(self, *parse_seed_fu_args(args, block)).seed end |