Created
October 12, 2017 14:50
-
-
Save HooFoo/2850627fbdc5147dddf9aa78a7326f2b to your computer and use it in GitHub Desktop.
Rails select
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 Category < ApplicationRecord | |
| acts_as_nested_set | |
| has_many :properties, dependent: :destroy | |
| has_and_belongs_to_many :items | |
| accepts_nested_attributes_for :properties, allow_destroy: true | |
| mount_uploader :icon, CategoryIconUploader | |
| scope :index, -> { where(parent_id: nil, show: true).order('items_count DESC').limit(10) } | |
| scope :main, -> { where(parent_id: nil, show: true).order('items_count DESC') } | |
| scope :for_select, -> (cat) { where.not(id: cat.id )} | |
| def to_s | |
| name | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment