Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class EmailTemplate < ActiveRecord::Base
- TEXT_PLAIN = 1
- TEXT_HTML = 2
- BOTH = TEXT_PLAIN | TEXT_HTML
- def after_initialize
- if new_record?
- self.content_types ||= BOTH
- end
- end
- def plain_text?
- (content_types & TEXT_PLAIN) ? true : false
- end
- def plain_text=(v)
- content_types ^= TEXT_PLAIN if v ^ plain_text?
- end
- def html?
- (content_types & TEXT_HTML) ? true : false
- end
- def html=(v)
- content_types ^= TEXT_HTML if v ^ html?
- end
- def formats
- returning [] do |a|
- a << 'text/plain' if content_types & TEXT_PLAIN
- a << 'text/html' if content_types & TEXT_HTML
- end
- end
- end
Add Comment
Please, Sign In to add comment