看起来你在寻找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"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
518 次 |
| 最近记录: |