What is the best way to make my table column read only? disable the setter method? The column is set by postgres trigger, so I don't want to set it in the application level
It seems like you look for 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With