How to pass focus property to text field in Ruby on Rails?

I'm having trouble setting focus on the text box for the Ruby on Rails login page. I want to focus on the user text field. Is there a way to provide the focus property for text_field?

+6
ruby-on-rails
source share
1 answer

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 is an HTML attribute.

+8
source share

All Articles