osem-fcy/app/models/role.rb
Ana María Martínez Gómez a8d2f8caa4
Drop halt_callback_chains_on_return_false
ActiveSupport.halt_callback_chains_on_return_false= is deprecated and
will be removed in Rails 5.2. Stop using it and return `throw(:abort)`
instead in the callbacks which need it.
2019-05-05 09:40:49 +02:00

23 lines
531 B
Ruby

# frozen_string_literal: true
class Role < ApplicationRecord
belongs_to :resource, polymorphic: true
has_many :users_roles
has_many :users, through: :users_roles
has_paper_trail on: [:create, :update], only: [:name, :description], meta: { conference_id: :resource_id }
before_destroy :cancel
scopify
validates :name, presence: true
validates :name, uniqueness: { scope: :resource }
private
# Needed to ensure that removing all user from role doesn't remove role.
def cancel
throw(:abort)
end
end