Maddy.Shik
Maddy.Shik

Reputation: 6787

Rails Model: How to make field read only in Rails model?

I have defined attribute is_first for table items.

In model Item, i want to set value of this attribute based upon whether an item exits before or not.
I don't want is_first attribute to be writeable. Please suggest what should i do?

Upvotes: 3

Views: 2580

Answers (1)

Matteo Alessani
Matteo Alessani

Reputation: 10412

you need to use attr_readonly in your model file:

attr_readonly :is_first

Upvotes: 9

Related Questions