Guest User

Untitled

a guest
Feb 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. class Site < ActiveRecord::Base
  2. has_many :pages
  3.  
  4. after_create :setup
  5.  
  6. def setup
  7. homepage = Page.from_yaml(YAML.load_file(RAILS_ROOT+'/lib/flower/default_homepage.yml'))
  8. self.pages << homepage
  9. homepage.publish!
  10. end
  11. end
  12.  
  13. class Page < ActiveRecord::Base
  14. belongs_to :site
  15. has_many :blocks, :as => :container, :dependent => :destroy, :order => 'position ASC', :extend => Container
  16.  
  17. class << self
  18. def from_yaml(values={})
  19. p = Page.new(:title => values['title'], :slug => values['slug'])
  20. if hsh['blocks']
  21. !! p.blocks = values['blocks'].collect {|block| Block.from_yaml(block) }
  22. end
  23. return p
  24. end
  25. end
  26. end
  27.  
  28. class Block < ActiveRecord::Base
  29. belongs_to :container, :polymorphic => true
  30. validates_presence_of :container
  31. end
  32.  
  33. !! >> s = Site.create(:domain => 'fqdn.com')
Add Comment
Please, Sign In to add comment