# Modify an AR model attribute before reading into form\_for

**URL:** <https://www.ruby-forum.com/t/modify-an-ar-model-attribute-before-reading-into-form-for/135159>\
**Category:** Rails\
**Created:** [April 18, 2008, 4:57pm UTC](https://www.ruby-forum.com/t/modify-an-ar-model-attribute-before-reading-into-form-for/135159 "2008-04-18T16:57:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [April 18, 2008, 4:57pm UTC](https://www.ruby-forum.com/t/modify-an-ar-model-attribute-before-reading-into-form-for/135159/1 "2008-04-18T16:57:12Z")

</div>

Hi,

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)  
end  
end

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 %\> \<%= @model.foo %\>  
\<% end %\>

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

Thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![harry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@harry](https://www.ruby-forum.com/u/harry)\
**Post date:** [April 18, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/modify-an-ar-model-attribute-before-reading-into-form-for/135159/2 "2008-04-18T18:06:37Z")

</div>

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?

Harry
