I'm folowing along with Railscast episode 235, where Ryan Bates integrates omniauth with Devise. After clicking sign-in with Twitter, his application takes him back to a form in his app where he has to enter an email address in the email field to complete the signup. (His username is already filled in the formdue to the way he wrote the session code). The form looks like this image below. Notice how he uses f.email_field where he enters his user name, even though he has a username field in the table. His app works successfully in the video.
I've downloaded his sourcecode but when I try to run it, I can't complete the signup unless I enter an email in the email field as well as email in the username field. I therefore changed the code to put a f.username_field
in the registration form
<div class="field"><%= f.label :username %><br />
<%= f.username_field :username %></div>
but I got this error
undefined method `username_field' for #<ActionView::Helpers::FormBuilder:0x007fc058a242c8>
:username is listed in the accessible attributes in the User.rb model, and this is the users table, with a username field, so I don't know why I'd get the 'undefined method' username_field. The app is only letting me enter an email address where the username label is
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "username"
t.string "provider"
t.string "uid"
end
Can you think of a reason why this might be happening?
email_field is probably using a helper that defines format.
Think of 'email_field' as in text_field or date_field except email_field means a field with the format rules used for email addresses.
So you can't pick and choose one of your model attributes plus '_field' the same way unless you define your own helper.
So instead of changing email_field
to username_field
, change it to text_field