# How to set text in text\_field\_tag?

**URL:** <https://www.ruby-forum.com/t/how-to-set-text-in-text-field-tag/128172>\
**Category:** Rails\
**Created:** [February 5, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/how-to-set-text-in-text-field-tag/128172 "2008-02-05T16:01:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eamonwssssssssss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/848f3c/32.png) [@eamonwssssssssss](https://www.ruby-forum.com/u/eamonwssssssssss)\
**Post date:** [February 5, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/how-to-set-text-in-text-field-tag/128172/1 "2008-02-05T16:01:21Z")

</div>

Simple problem but I can’t find a solution.

I have this tag:

\<%=text\_field\_tag(“query”, params[:query], :autocomplete =\> “off” ) %\>

Its a search field box.

Question: how do I update the text in the text field??? i.e is there a  
rails equivalent like query.setText(“some text”)

Thanks

---

<div class="post-metadata">

**Author:** ![eamonwssssssssss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/848f3c/32.png) [@eamonwssssssssss](https://www.ruby-forum.com/u/eamonwssssssssss)\
**Post date:** [February 5, 2008, 5:00pm UTC](https://www.ruby-forum.com/t/how-to-set-text-in-text-field-tag/128172/2 "2008-02-05T17:00:04Z")

</div>

> **[ActionView::Helpers::FormTagHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M001038)**
>
> Provides a number of methods for creating form tags that don't rely on an Active Record object assigned to the template like FormHelper does. Instead, you provide the names and values manually.

The second argument is the value you want it to be … so, default  
params[:query] in your controller, or do something like this

\<%=text\_field\_tag(“query”, params[:query] || “Some  
value”, :autocomplete =\> “off” ) %\>

in-line || allows you to specify something if the value before the ||  
is nil, another useful thing, e.g. in the controller

params[:query] ||= “Some value”

This will set the value if params[:query] is nil

HTH
