Skip to content

Instantly share code, notes, and snippets.

@HooFoo
Created October 12, 2017 14:50
Show Gist options
  • Select an option

  • Save HooFoo/2850627fbdc5147dddf9aa78a7326f2b to your computer and use it in GitHub Desktop.

Select an option

Save HooFoo/2850627fbdc5147dddf9aa78a7326f2b to your computer and use it in GitHub Desktop.
Rails select
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