Sha256: bd6967d15daf06227d114b2f72bbd85eb15c77d366c83b33bbaaaadde825bad9

Contents?: true

Size: 805 Bytes

Versions: 5

Compression:

Stored size: 805 Bytes

Contents

  has_paper_trail
  slugged :recognizable_name
  flag_attrs :published
  acts_as_nested_set
  acts_as_recognizable :recognizable_name

  after_save :update_descendants_states

  validates :name, presence: true

  scope :sorted, -> { order('lft ASC') }

  def reasonable_name
    if self.respond_to?(:translations)
      name.presence || translations.detect { |t| t.name.present? }.try(:name)
    else
      name
    end
  end

  def recognizable_name
    slug.present? ? slug : reasonable_name
  end

  def update_descendants_states
    if saved_change_to_published? && !published?
      self.class.unscoped.where(parent_id: id).set_each_published_off
    end
  end

  alias_method :destroy_orig, :destroy
  def destroy
    safe_destroy(children_to: :parent, without_destroy: true)
    destroy_orig
  end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
adminos-1.0.0.pre.rc.5 lib/generators/templates/adminos/types/sortable/model.rb
adminos-1.0.0.pre.rc.4 lib/generators/templates/adminos/types/sortable/model.rb
adminos-1.0.0.pre.rc.3 lib/generators/templates/adminos/types/sortable/model.rb
adminos-1.0.0.pre.rc.2 lib/generators/templates/adminos/types/sortable/model.rb
adminos-1.0.0.pre.rc.1 lib/generators/templates/adminos/types/sortable/model.rb