Arpit Vaishnav
Arpit Vaishnav

Reputation: 4780

How to give focus property to text box in Ruby on Rails?

I have a problem with setting the focus to the textbox for a login page in Ruby on Rails. I want to give focus to a user text field. Is there any way to give focus property to text_field?

Upvotes: 6

Views: 2691

Answers (1)

Cimm
Cimm

Reputation: 4775

In HTML5 you can do something like this:

<%= f.text_field :my_field, :autofocus => true %> 

The only way to achieve this without using HTML 5 is with JavaScript if I'm not mistaken. This has nothing to do with Rails, it's an HTML attribute.

Upvotes: 8

Related Questions