Is there an easy way to make a Rails ActiveRecord model read-only?

后端 未结 8 1283
-上瘾入骨i
-上瘾入骨i 2021-01-31 01:25

I want to be able to create a record in the DB but then prevent Rails from making changes from that point on. I understand changes will still be possible at the DB level.

8条回答
  •  难免孤独
    2021-01-31 02:12

    This blog post is still valid: http://ariejan.net/2008/08/17/activerecord-read-only-models/

    Basically you can rely on ActiveRecord's validation if you add a method:

    def readonly?
      true
    end
    

提交回复
热议问题