# Setting default value in text\_field/password\_field

**URL:** <https://www.ruby-forum.com/t/setting-default-value-in-text-field-password-field/114917>\
**Category:** Rails\
**Created:** [September 18, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/setting-default-value-in-text-field-password-field/114917 "2007-09-18T19:50:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![will](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/90ced4/32.png) [@will](https://www.ruby-forum.com/u/will)\
**Post date:** [September 18, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/setting-default-value-in-text-field-password-field/114917/1 "2007-09-18T19:50:21Z")

</div>

I am trying to set a default value in a text\_field form. I know how  
to do this in html, but is there a way to do  
this with form\_for

Here is my code

\<% form\_for :user do |f| -%\>

First Name  
\<%= f.text\_field :firstname%\>

...

Email  
\<%=f.text\_field :email %\>

Password  
\<%=f.password\_field :password %\>

...

\<%= submit\_tab 'Sign up' %\>

\<% end -%\>

I would like to produce something of this type for both text\_field and  
password\_field  
  
Any ideas???

---

<div class="post-metadata">

**Author:** ![will](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/90ced4/32.png) [@will](https://www.ruby-forum.com/u/will)\
**Post date:** [September 18, 2007, 10:18pm UTC](https://www.ruby-forum.com/t/setting-default-value-in-text-field-password-field/114917/2 "2007-09-18T22:18:51Z")

</div>

Hi, you should be able to do the following as stated in the Rails  
Framework  
Documentation:

\<%= f.text\_field :email, options =\> { :value =\> “removed\_email\_address@domain.invalid” }  
%\>

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![will](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/90ced4/32.png) [@will](https://www.ruby-forum.com/u/will)\
**Post date:** [September 18, 2007, 10:19pm UTC](https://www.ruby-forum.com/t/setting-default-value-in-text-field-password-field/114917/3 "2007-09-18T22:19:52Z")

</div>

On 9/18/07, Will [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= f.text\_field :firstname%\>
> 
>   
> I would like to produce something of this type for both text\_field and  
> password\_field

The initial values will be taken from @user, so populate that  
(typically in the controller) before rendering your template.

@user = User.new(:email = “removed\_email\_address@domain.invalid”)  
… then render the template
