Last active
December 1, 2016 10:16
-
-
Save staycreativedesign/ee10cca60d5fca00df512ed1af9a7e3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= f.select :path, Page.all.collect {|p|[p.url_link_name, p.slug ] } << ["blogs", "/blogs"] << ["none", "#"] << ["home", "/"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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