在使用railscast(http://railscasts.com/episodes/235-omniauth-part-1)後,我在我的rails3應用程序中使用了devise和omniauth。devise和omniauth未找到用戶名登錄
我可以登錄,並在數據庫中看到sign_in_count列正在增加。
但是,user_signed_in?
總是返回false,並且current_user?
返回no method error
。
我見過其他答案,說問題是由rails.js引起的,但我沒有使用rails.js。
我控制器
def create omniauth = request.env["omniauth.auth"] authentication = Authentication.find_by_provider_and_uid(omniauth['provider'],omniauth['uid']) if authentication sign_in_and_redirect(:user, authentication.user) elsif current_user current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid']) redirect_to root_url else user = User.new user.apply_omniauth(omniauth) if user.save(:validate => false) sign_in(:user, user) redirect_to root_url else flash[:notice] = "error creating account" redirect_to root_url end end end
在你的用戶模型中,你有一句話說'devise:omniauthable,...'?如果沒有,你需要一個用戶模型(或者如果你的模型被稱爲別人喜歡的人,那麼你實際上需要'person_signed_in?'和'current_person') – ronalchn
@ronalchn當我添加omniauthable,我得到一個路由錯誤'沒有路由匹配/ auth/facebook'我認爲出路的方式是不包括omniauthable。 – pedalpete
那麼,我沒有用omgnuthable設計,所以我不知道。但是我知道你需要在你的User模型中調用設計函數(即使你沒有使用其他模塊的參數)。 – ronalchn