Rails中是否有禁止对所有activerecord对象执行任何操作(插入/销毁)的方法
我想要一个不允许任何东西改变数据库状态的设置。然后,我希望能够增量白名单允许的操作 扩展activerecord库Rails中是否有禁止对所有activerecord对象执行任何操作(插入/销毁)的方法,activerecord,Activerecord,我想要一个不允许任何东西改变数据库状态的设置。然后,我希望能够增量白名单允许的操作 扩展activerecord库 class MyAuthoritarianRecord < ActiveRecord::Base belongs_to :user # crazy logic here def destroy if user.wont_submit_to_bondage_and_discipline? # silently fail else
class MyAuthoritarianRecord < ActiveRecord::Base
belongs_to :user
# crazy logic here
def destroy
if user.wont_submit_to_bondage_and_discipline?
# silently fail
else
super
end
end
end
class PropertyOfTheState < MyAuthoritarianRecord
end
class MyAuthoriatorRecord
对于资源,您可以为config/routes.rb
文件中的相应资源添加除了:[:新建,:创建,:更新,:销毁]