Q:

How do you add text inside a text field in Rails?

I would like to add username inside the username text field in my application (vs having a label next to it) the user would be able to type over this text. I've seen it done in html but I'm confused as to how to do it on my new.html.erb page since im using the form_for tag and the text_field tag.
thanks in advanced!

A:

Use "placeholder".
<%= form_for @user do |f| %>
  <%= f.text_field :username, :placeholder => "Username" %>

  ...

  <%= f.submit %>
<% end %>

This will only work for html5 supported browsers by the way, so make sure you have jquery fallback for IE 8, 7 etc.

