Class: InitialData

Inherits:
Object
  • Object
show all
Extended by:
Cms::DataLoader
Defined in:
lib/initial_data.rb

Class Method Summary collapse

Methods included from Cms::DataLoader

create, method_missing

Class Method Details

.load_demoObject

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)



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/initial_data.rb', line 11

def self.load_demo
  eval open("#{Rails.root}/db/demo/data.rb"){|f| f.read}
  
  Dir["#{Rails.root}/db/demo/page_partials/*.erb"].map do |f|
    name, format, handler = File.basename(f).split('.')
    create_page_partial(name.to_sym, 
      :name => name, :format => format, :handler => handler,
      :body => open(f){|f| f.read})
  end
  
  Dir["#{Rails.root}/db/demo/page_templates/*.erb"].map do |f|
    name, format, handler = File.basename(f).split('.')
    create_page_template(name.to_sym, 
      :name => name, :format => format, :handler => handler,
      :body => open(f){|f| f.read})
  end
  
end