Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Page < ActiveRecord::Base
- belongs_to :list
- belongs_to :menu_option, dependent: :destroy
- def save_and_create_menu_option
- transaction do
- begin
- self.save!
- create_menu_option(self)
- true
- rescue
- ActiveRecord::Rollback
- false
- end
- end
- end
- private
- def create_menu_option(page)
- MenuOption.create!(
- {
- title: page.title,
- item_type: :page,
- visible: false,
- list: page.list,
- page: page
- }
- )
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement