2016-05-08 35 views

回答

3

好像你找的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"