# Value for text\_field\_tag?

**URL:** <https://rubytalk.org/t/value-for-text-field-tag/56729>\
**Category:** ruby-talk\
**Created:** [21 December 2009 11:35 UTC](https://rubytalk.org/t/value-for-text-field-tag/56729 "2009-12-21T11:35:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_P1](https://avatars.discourse-cdn.com/v4/letter/t/f9ae1b/32.png) [@T\_P1](https://rubytalk.org/u/T_P1)\
**Post date:** [21 December 2009 11:35 UTC](https://rubytalk.org/t/value-for-text-field-tag/56729/1 "2009-12-21T11:35:17Z")

</div>

Hi!

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

In the view, I have this code:  
&nbsp;&nbsp;\<%= label\_tag('data[text]', "Word/phrase: ") %\> \<br /\>  
&nbsp;&nbsp;\<%= 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,  
&nbsp;&nbsp;\<%= text\_field\_tag( 'data[text]', 'STATIC STRING', :size =\>  
40, :maxlength =\> 254 ) %\>

What am I missing here? :-/

Tuo

---

<div class="post-metadata">

**Author:** ![Inaki\_Baz\_Castillo](https://avatars.discourse-cdn.com/v4/letter/i/f14d63/32.png) [@Inaki\_Baz\_Castillo](https://rubytalk.org/u/Inaki_Baz_Castillo)\
**Post date:** [21 December 2009 11:51 UTC](https://rubytalk.org/t/value-for-text-field-tag/56729/2 "2009-12-21T11:51:42Z")

</div>

Please, ask in a list of RubyOnRails.

> **···**
>
> El Lunes, 21 de Diciembre de 2009, T\_P escribió:
> 
> > Hi!
> > 
> > I have this in my controller:  
> > @text = params[:data][:text]
> > 
> > In the view, I have this code:  
> > &nbsp;&nbsp;\<%= label\_tag('data[text]', "Word/phrase: ") %\> \<br /\>  
> > &nbsp;&nbsp;\<%= 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,  
> > &nbsp;&nbsp;\<%= text\_field\_tag( 'data[text]', 'STATIC STRING', :size =\>  
> > 40, :maxlength =\> 254 ) %\>
> > 
> > What am I missing here? :-/
> 
> --  
> Iñaki Baz Castillo \<ibc@aliax.net\>
