Sha256: 3e6d3ddaf82a0421afcd6180621b195c53f4cb7713baee22a3c5bb141858fe0d
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
class Permission < ApplicationRecord # Associations belongs_to :user belongs_to :feature # Validations validates :can_create, inclusion: { in: [true, false] } validates :can_read, inclusion: { in: [true, false] } validates :can_update, inclusion: { in: [true, false] } validates :can_delete, inclusion: { in: [true, false] } # ------------------ # Class Methods # ------------------ # return an active record relation object with the search query in its where clause # Return the ActiveRecord::Relation object # == Examples # >>> permission.search(query) # => ActiveRecord::Relation object scope :search, lambda {|query| joins("INNER JOIN users u on permissions.user_id = u.id"). joins("INNER JOIN features f on permissions.feature_id = f.id"). where("LOWER(u.name) LIKE LOWER('%#{query}%') OR\ LOWER(u.username) LIKE LOWER('%#{query}%') OR\ LOWER(u.email) LIKE LOWER('%#{query}%') OR\ LOWER(f.name) LIKE LOWER('%#{query}%')")} end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
usman-0.1.0 | app/models/permission.rb |