我跟隨Railscast第235集一起,Ryan Bates將omniauth與Devise集成在一起。用Twitter點擊登錄後,他的應用程序將他帶回應用程序中的表單,他必須在電子郵件字段中輸入電子郵件地址才能完成註冊。 (他的用戶名已經填寫在他寫會話代碼的方式中)。窗體如下圖所示。注意他如何使用f.email_field在哪裏輸入他的用戶名,即使他在表中有一個用戶名字段。他的應用在視頻中成功運行。即使表中的用戶名沒有用戶名字段
我已經下載了源代碼,但是當我嘗試運行它,除非我的用戶名字段中輸入在電子郵件字段中的電子郵件以及電子郵件我無法完成註冊。因此,我改變了代碼把一個f.username_field
登記表
<div class="field"><%= f.label :username %><br />
<%= f.username_field :username %></div>
,但我得到這個錯誤
undefined method `username_field' for #<ActionView::Helpers::FormBuilder:0x007fc058a242c8>
:用戶名在User.rb模型的訪問屬性上市了,這是用戶表,用戶名字段,所以我不知道爲什麼我會得到'未定義的方法'username_field。該應用僅讓其中的用戶名標籤
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
你能想到的一個原因,這可能發生我輸入電子郵件地址?
他補充說,用戶名,以表他創造了色器件的用戶之後。也許設計人員爲email_field創建了幫手,但由於當時用戶名並不存在,所以沒有提供。 – Leahcim 2013-02-13 03:01:26
解決了這個問題。謝謝,我會爲你投票給你 – Leahcim 2013-02-13 03:03:42