# Sorry that this question is so dumb but

**URL:** <https://www.ruby-forum.com/t/sorry-that-this-question-is-so-dumb-but/48152>\
**Category:** Rails\
**Created:** [November 17, 2005, 5:12am UTC](https://www.ruby-forum.com/t/sorry-that-this-question-is-so-dumb-but/48152 "2005-11-17T05:12:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [November 17, 2005, 5:12am UTC](https://www.ruby-forum.com/t/sorry-that-this-question-is-so-dumb-but/48152/1 "2005-11-17T05:12:44Z")

</div>

OK. This is embarrassing.

I need to programatically set the value of a field on a form (I get  
the id of the last invoice created and want to populate a hidden  
field on the line\_items form with that number so that the line items  
know to which invoice they belong). Its easy in HTML but I am using  
the rails text\_field method. I guessed at setting :value but it does  
not seem to do anything.

Well, I’ve looked for a good hour now and can find no record of it.  
Please would someone help me.

bruce

PS. If it was in the api docs or the Agile web development book,  
please feel free to send abuse with your answer. I’ll take it in  
good cheer.

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [November 17, 2005, 6:03am UTC](https://www.ruby-forum.com/t/sorry-that-this-question-is-so-dumb-but/48152/2 "2005-11-17T06:03:59Z")

</div>

On 17/11/2005, at 3:10 PM, Bruce B. wrote:

> I need to programatically set the value of a field on a form (I  
> get the id of the last invoice created and want to populate a  
> hidden field on the line\_items form with that number so that the  
> line items know to which invoice they belong). Its easy in HTML but  
> I am using the rails text\_field method. I guessed at setting :value  
> but it does not seem to do anything.

Typically you’d set it in the controller. You probably have  
something like @mything = Thing.new() in the “new” action in your  
controller. So to pre-fill the invoice id, you can try something like.

@mything = Thing.new()  
@mything.invoice\_id = 25

Then \<%= text\_field “mything”, “invoice\_id” %\> will automatically be  
populated with the value “25”.

Without seeing an example of your existing controller and view,  
you’ll have to make the leap from this example to making it work in  
your code, but that should be enough to get you started.

* * *

Justin F., Indent.com.au  
removed\_email\_address@domain.invalid  
Web Application Development & Graphic Design

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [November 17, 2005, 7:25am UTC](https://www.ruby-forum.com/t/sorry-that-this-question-is-so-dumb-but/48152/3 "2005-11-17T07:25:35Z")

</div>

Hi Bruce,

I’m not sure if you checked the docs on this but

[http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html#M000334](http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html#M000334)

(I found the docs difficult to navigate at first but I’m starting to get  
the  
hang of them now.)

- Peter
