Modify an AR model attribute before reading into form_for


I’m trying to modify an AR model’s foo attribute before reading into
the model’s edit form. I’ve tried the following:

class Model
def foo
"the foo attribute is " + read_attribute(:foo)

If I use a form_for on the edit view with the following code, I get
the plain database value inside the text field and the AR value next
to it:

<% form_for(@model) do |f| %>
<%= f.text_field, :foo %> <%= %>
<% end %>

It seems like they should show the same value but they don’t. What am
I missing?


More on this topic. If I use a plain HTML input tag like so:

I get the correct value in the input box.

Does anyone know how FormBuilder gets its values? Is this a bug or is
it expected?