Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class Page < ActiveRecord::Base
  2. belongs_to :list
  3. belongs_to :menu_option, dependent: :destroy
  4.  
  5. def save_and_create_menu_option
  6. transaction do
  7. begin
  8. self.save!
  9. create_menu_option(self)
  10. true
  11. rescue
  12. ActiveRecord::Rollback
  13. false
  14. end
  15. end
  16. end
  17.  
  18. private
  19. def create_menu_option(page)
  20. MenuOption.create!(
  21. {
  22. title: page.title,
  23. item_type: :page,
  24. visible: false,
  25. list: page.list,
  26. page: page
  27. }
  28. )
  29. end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement