app/models/cambium/page.rb in cambium-1.3.0 vs app/models/cambium/page.rb in cambium-1.3.1

- old
+ new

@@ -20,10 +20,11 @@ # ------------------------------------------ Callbacks after_save :cache_page_path after_save :reload_routes! + after_save :expire_caches # ------------------------------------------ Class Methods def self.home where(:is_home => true).published.first @@ -51,11 +52,13 @@ path.collect(&:title).join(' : ') end def method_missing(method, *arguments, &block) if respond_to?(method.to_s) - if template.fields[method.to_s]['type'] == 'media' + if template.fields[method.to_s.gsub(/\?$/, '')]['type'] == 'boolean' + template_data[method.to_s.gsub(/\?$/, '')].to_i == 1 + elsif template.fields[method.to_s]['type'] == 'media' Cambium::Document.find_by_id(template_data[method.to_s].to_i) else template_data[method.to_s] end else @@ -65,10 +68,13 @@ def respond_to?(method, include_private = false) return true if super return false if template.blank? return true if template.fields.keys.include?(method.to_s) + template.fields.each do |name, attrs| + return true if attrs["type"] == 'boolean' && method.to_s == "#{name}?" + end false end private @@ -76,9 +82,13 @@ Rails.application.reload_routes! end def cache_page_path update_columns(:page_path => "/#{path.collect(&:slug).join('/')}") + end + + def expire_caches + Rails.cache.delete_matched(/\_p#{id}(.*)/) end end end