Preventing AR from writing a certain field?

One of my models have a field that should be maintained exclusively by
triggers.

I could always create a view that masks this column from updates, but
if there’s a decent way to accomplish this with just AR, I’d rather go
for that.

Suggestions appreciated,
Isak

From Rails API Docs:

attr_protected(*attributes)
Attributes named in this macro are protected from mass-assignment, such
as new(attributes) and attributes=(attributes). Their assignment will
simply be ignored. Instead, you can use the direct writer methods to do
assignment. This is meant to protect sensitive attributes from being
overwritten by URL/form hackers.

class Customer < ActiveRecord::Base
attr_protected :credit_rating
end

by setting this for an attribute (column), you always have to
explicitly change it like

@something.attribute = “bla”
or with your toggle.
@something = @something.toggle(:attribute)

On 11/9/06, Isak H. [email protected] wrote:

One of my models have a field that should be maintained exclusively by triggers.

I could always create a view that masks this column from updates, but
if there’s a decent way to accomplish this with just AR, I’d rather go
for that.

Thinking about it, I decided to put this in the db layer. Best way to
guarantee integrity, no matter what happens to this app in the future.

Isak