Question

I am trying to find a Rails-way of putting a simple placeholder into a form I have made for a contact page. The code is as follows:

<div class="form-group">
<%= label_tag(:email, "email") %>
<%= email_field(:user, :address) %>
</div>

Where would I put placeholder code, and how would I do it in this context. I want it to say "ex: joe@joe.com" in the field until it is clicked on.

I am using Ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0], and Rails 4.0.0.

Was it helpful?

Solution

You'd put the placeholder in your email input.

email_field returns a text_field of type email, so appending the placeholder attribute to the end of the parameter list in your email_field helper call should produce the expected result:

<div class="form-group">
  <%= label_tag(:email, "email") %>
  <%= email_field(:user, :address, placeholder: 'ex: joe@joe.com') %>
</div>

OTHER TIPS

<div class="form-group">
<%= label_tag :email => "email" %>
<%= email_field :user, :address, :placeholder => "ex: joe@joe.com" %>
</div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top