Class | InitialData |
In: |
lib/initial_data.rb
|
Parent: | Object |
Fixture-like way of creating initial data, except that it actually calls the real model methods This way things like acts_as_list and versioning get setup properly for these records The syntax is that you call create_whatever(:something, …), where whatever is the model name, something is the identifier you give this record, and the … is the hash of options to pass to the model constructor. By calling the create_ method, you can then refer to the record later in the same way you would with fixtures, by saying whatevers(:something)
# File lib/initial_data.rb, line 11 11: def self.load_demo 12: eval open("#{Rails.root}/db/demo/data.rb"){|f| f.read} 13: 14: Dir["#{Rails.root}/db/demo/page_partials/*.erb"].map do |f| 15: name, format, handler = File.basename(f).split('.') 16: create_page_partial(name.to_sym, 17: :name => name, :format => format, :handler => handler, 18: :body => open(f){|f| f.read}) 19: end 20: 21: Dir["#{Rails.root}/db/demo/page_templates/*.erb"].map do |f| 22: name, format, handler = File.basename(f).split('.') 23: create_page_template(name.to_sym, 24: :name => name, :format => format, :handler => handler, 25: :body => open(f){|f| f.read}) 26: end 27: 28: end