ruby-on-rails – 使Rails表列属性为只读
发布时间:2020-12-17 02:56:25 所属栏目:百科 来源:网络整理
导读:使表格列只读的最佳方法是什么?禁用setter方法?该列由postgres触发器设置,因此我不想在应用程序级别设置它 解决方法 看起来你好像在寻找ActiveRecord :: Base attr_readonly : class Foo ActiveRecord::Base attr_readonly :barendfoo = Foo.create(bar:
使表格列只读的最佳方法是什么?禁用setter方法?该列由postgres触发器设置,因此我不想在应用程序级别设置它
解决方法
看起来你好像在寻找ActiveRecord :: Base
attr_readonly :
class Foo < ActiveRecord::Base attr_readonly :bar end foo = Foo.create(bar: "first_value") foo.bar => "first_value" foo.update(bar: "second_value") #column `bar` ignored in SQL query foo.bar => "first_value" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |