How to extend a Post Model?

By this way you can extend, overwrite a Camaleon CMS Post Model.

  • Create an initializer
    # config/initializers/my_custom_cama_post.rb
    Rails.application.config.to_prepare do
    CamaleonCms::Post.class_eval do

    # add custom relationships
    has_many :my_items
    belongs_to :custom_item

    # overwrite an existent method
    def total_visits
    # custom logic to get the total visits
    end

    # add a new method
    def my_custom_method
    # ....
    end
    end
    end
  • Samples: (before restart server)
    my_post.my_items
    my_post.custom_item
    my_post.total_visits
    my_post.my_custom_method

Created at: 23 Jan 11:36 | Updated at: 23 Jan 11:36