fancy-crowd-87619
04/27/2023, 6:46 PMdef attach_user? = false
def detach_user? = false
def create_user? = false
Anyone know a nice way to make all of these relationship abilities false
by default?lemon-wall-20836
04/27/2023, 6:59 PMlemon-wall-20836
04/27/2023, 7:00 PMlemon-wall-20836
04/27/2023, 7:01 PMApplicationPolicy
create a class method that takes the association name (user
) and have it create those methods dynamicallylemon-wall-20836
04/27/2023, 7:01 PMlemon-wall-20836
04/27/2023, 7:02 PMdisable_association :user
lemon-wall-20836
04/27/2023, 7:02 PMruby
def attach_user? = false
def detach_user? = false
def create_user? = false
lemon-wall-20836
04/27/2023, 7:04 PMfancy-crowd-87619
04/27/2023, 7:05 PMfancy-crowd-87619
04/27/2023, 7:06 PMlemon-wall-20836
04/27/2023, 7:06 PMlemon-wall-20836
04/27/2023, 7:07 PMAvo::App.get_resource_by_model_name("MODEL_NAME")
and go through the fields
. the field.type
will be belongs_to
, has_many
, etc.lemon-wall-20836
04/27/2023, 7:08 PMfancy-crowd-87619
04/27/2023, 7:09 PMfancy-crowd-87619
04/27/2023, 7:09 PMlemon-wall-20836
04/27/2023, 7:09 PMfancy-crowd-87619
04/28/2023, 12:51 AMruby
module Avo
module Concerns
module PolicyHelpers
extend ActiveSupport::Concern
class_methods do
def disable_association_management(association_name)
%i[attach detach create].each do |method_action|
define_policy_method(method_action, association_name)
end
end
private
# Define a method for the given action and association name.
def define_policy_method(method_action, association_name)
define_method "#{method_action}_#{association_name}?" do
false
end
end
end
end
end
end
fancy-crowd-87619
04/28/2023, 12:51 AMfancy-crowd-87619
04/28/2023, 12:52 AMlemon-wall-20836
04/28/2023, 8:01 AMlemon-wall-20836
04/28/2023, 8:01 AM