# Value for text\_field\_tag?

**URL:** <https://www.ruby-forum.com/t/value-for-text-field-tag/180530>\
**Category:** Ruby\
**Created:** [December 21, 2009, 12:41pm UTC](https://www.ruby-forum.com/t/value-for-text-field-tag/180530 "2009-12-21T12:41:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/41988e/32.png) [@T\_P](https://www.ruby-forum.com/u/T_P)\
**Post date:** [December 21, 2009, 12:41pm UTC](https://www.ruby-forum.com/t/value-for-text-field-tag/180530/1 "2009-12-21T12:41:01Z")

</div>

Hi!

I have this in my controller:  
@text = params[:data][:text]

In the view, I have this code:  
\<%= label\_tag(‘data[text]’, "Word/phrase: ") %\>   
  
\<%= text\_field\_tag( ‘data[text]’, @text, :size =\> 40, :maxlength =\>  
254 ) %\>

What I would like to have is to get a default value for the form  
field. I cannot figure out why @text controller instance variable  
doesn’t work. It’s a non-empty string, but the corresponding form  
field is always blank. ☹

However, this piece of code always works,  
\<%= text\_field\_tag( ‘data[text]’, ‘STATIC STRING’, :size =\>  
40, :maxlength =\> 254 ) %\>

What am I missing here? :-/

Tuo

---

<div class="post-metadata">

**Author:** ![T\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/41988e/32.png) [@T\_P](https://www.ruby-forum.com/u/T_P)\
**Post date:** [December 21, 2009, 12:55pm UTC](https://www.ruby-forum.com/t/value-for-text-field-tag/180530/2 "2009-12-21T12:55:39Z")

</div>

El Lunes, 21 de Diciembre de 2009, T\_P  
escribió:\> What I would like to have is to get a default value for the form

> field. I cannot figure out why @text controller instance variable  
> doesn’t work. It’s a non-empty string, but the corresponding form  
> field is always blank. ☹
> 
> However, this piece of code always works,  
> \<%= text\_field\_tag( ‘data[text]’, ‘STATIC STRING’, :size =\>  
> 40, :maxlength =\> 254 ) %\>
> 
> What am I missing here? :-/

Please, ask in a list of RubyOnRails.
