# Automatically filling a text box

**URL:** <https://www.ruby-forum.com/t/automatically-filling-a-text-box/135403>\
**Category:** Rails\
**Created:** [April 21, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/automatically-filling-a-text-box/135403 "2008-04-21T22:39:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@ryank](https://www.ruby-forum.com/u/ryank)\
**Post date:** [April 21, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/automatically-filling-a-text-box/135403/1 "2008-04-21T22:39:41Z")

</div>

Well I am new to Rails and I’m looking to find out how to  
automatically fill a text box with a randomly generated password. I  
can generate and display the password just fine but I cannot find a  
way to have the page load with the password already in the text field.

Regards,

Ryan

---

<div class="post-metadata">

**Author:** ![ryank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@ryank](https://www.ruby-forum.com/u/ryank)\
**Post date:** [April 21, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/automatically-filling-a-text-box/135403/2 "2008-04-21T23:06:16Z")

</div>

Hrmmm…

like in the controller, if it’s a User that has a password, you can’t  
just do:

def new  
@user = User.new  
@user.password = ‘ryans\_text’  
respond\_to do |format|  
format.html # new.html.erb  
format.xml { render :xml =\> @user }  
end  
end

and have ‘ryans\_text’ appear in the password field of the form???

Generally, you’ll not want passwords in a plain text\_field… and a  
password\_field won’t show the text on purpose.

---

<div class="post-metadata">

**Author:** ![ryank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@ryank](https://www.ruby-forum.com/u/ryank)\
**Post date:** [April 21, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/automatically-filling-a-text-box/135403/3 "2008-04-21T23:17:37Z")

</div>

On 4/21/08, Ryan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Well I am new to Rails and I’m looking to find out how to  
> automatically fill a text box with a randomly generated password. I  
> can generate and display the password just fine but I cannot find a  
> way to have the page load with the password already in the text field.

You can set it in the controller when you make a new instance of the  
object:

@foo = Foo.new( :passwd =\> passwd )

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![ryank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@ryank](https://www.ruby-forum.com/u/ryank)\
**Post date:** [April 22, 2008, 3:09am UTC](https://www.ruby-forum.com/t/automatically-filling-a-text-box/135403/4 "2008-04-22T03:09:18Z")

</div>

user form\_for method

> **[ActionView::Helpers::FormHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html)**
>
> Form helpers are designed to make working with resources much easier compared to using vanilla HTML.
