Module: BcmsBitly::PageExtender
- Defined in:
- lib/bcms_bitly/page_extender.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(model) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bcms_bitly/page_extender.rb', line 3 def self.included(model) model.after_save :bcms_bitly_create_short_link model.has_one :short_link, class_name: 'BcmsBitly::ShortLink' def bcms_bitly_create_short_link if persisted? return unless path_changed? end domain = Rails.configuration.cms.site_domain sl = short_link || build_short_link sl.url = sl.shorten("http://#{domain}#{path}") sl.name = name self.short_link = sl self.short_link.save! self.short_link.publish! end end |
Instance Method Details
#bcms_bitly_create_short_link ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bcms_bitly/page_extender.rb', line 7 def bcms_bitly_create_short_link if persisted? return unless path_changed? end domain = Rails.configuration.cms.site_domain sl = short_link || build_short_link sl.url = sl.shorten("http://#{domain}#{path}") sl.name = name self.short_link = sl self.short_link.save! self.short_link.publish! end |