Class: AlchemyCrm::Seeder

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemy_crm/seeder.rb

Class Method Summary collapse

Class Method Details

.seed!Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/alchemy_crm/seeder.rb', line 4

def self.seed!
  puts "Seeding database for Alchemy Mailing Module"
  root = Alchemy::Page.root
  lang = Alchemy::Language.get_default
  if root.nil? || lang.nil?
    puts "== Aborting! Not all dependencies found. Did you ran the Alchemy seeder?"
  else
    mailing_root = Alchemy::Page.find_or_create_by_name(
      :name => "Alchemy CRM Rootpage",
      :page_layout => 'alchemy_crm_rootpage',
      :do_not_autogenerate => true,
      :do_not_sweep => true,
      :language => lang,
      :parent_id => root.id
    )
    if mailing_root.new_record?
      mailing_root.save!
      mailing_root.move_to_child_of root
      puts "== Success! Mailing root page created"
    else
      puts "== Skipping! Already created mailing root page."
    end
  end
end