Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Last active December 1, 2016 10:16
Show Gist options
  • Save staycreativedesign/ee10cca60d5fca00df512ed1af9a7e3d to your computer and use it in GitHub Desktop.
Save staycreativedesign/ee10cca60d5fca00df512ed1af9a7e3d to your computer and use it in GitHub Desktop.
= f.select :path, Page.all.collect {|p|[p.url_link_name, p.slug ] } << ["blogs", "/blogs"] << ["none", "#"] << ["home", "/"]
class Page < ActiveRecord::Base
mount_uploader :image, PageLeftImageUploader
has_many :subcategories, -> { order(position: :asc)}
extend FriendlyId
friendly_id :url_link_name, use: :slugged
acts_as_list scope: :nav_menu
default_scope { order(position: :asc) }
end
class Subcategory < ActiveRecord::Base
mount_uploader :image, LeftImageUploader
belongs_to :page
extend FriendlyId
friendly_id :url_link_name, use: :slugged
acts_as_list scope: :page
def parent_id
self.page_id
end
def position_count
Subcategory.where("position IS NOT NULL").where("page_id = ?", self.page_id).count
end
def self.active_links
Subcategory.where("position IS NOT NULL")
end
def hierarchy_list
"#{self.page.url_link_name} > #{self.url_link_name}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment