kamusett
kamusett

Reputation: 1403

Set autofocus => true in custom_fields added on devise

I've added 2 new fields on my devise users: :first_name and :last_name

So in the registration page I've added these new fields to be filled by user.

  <div>
    <%= f.label :first_name %> <br>
    <%= f.text_field :first_name, autofocus => true %>
  </div>

  <div>
    <%= f.label :last_name %> <br>
    <%= f.text_field :last_name %>
  </div>

  <div><%= f.label :email %><br />
  <%= f.email_field :email %></div>

  <div><%= f.label :password %><br />
  <%= f.password_field :password %></div>

  <div><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %></div>

Initially the autofocus was set on :email field, but now I changed to :first_name field.

The problem is when I access this page i get this error:

undefined local variable or method `autofocus' for #<#<Class:0x361ef18>:0x449d630>

What forgot I to do in my rails app?

Upvotes: 0

Views: 1472

Answers (2)

Amol Pujari
Amol Pujari

Reputation: 2349

it should be :autofocus and not autofocus

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

The colon : is missing at the start, should be a symbol, else its treated as if local variable/assign.

Upvotes: 3

zwippie
zwippie

Reputation: 15515

You forgot the : before the autofocus symbol, change it to:

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

Upvotes: 3

Related Questions