Ruby on rails &引用;OmniAuthCallbackController#facebook中的命名错误:未定义的方法“utc';2014年9月29日星期一:日期;从使用导轨和MongoMapper的设计
在过去的两周里,我一直在利用空闲时间尝试让VoteSquared.org()的Facebook身份验证工作。_和_重定向中的符号_是发生错误的位置:Ruby on rails &引用;OmniAuthCallbackController#facebook中的命名错误:未定义的方法“utc';2014年9月29日星期一:日期;从使用导轨和MongoMapper的设计,ruby-on-rails,ruby,facebook,mongodb,devise,Ruby On Rails,Ruby,Facebook,Mongodb,Devise,在过去的两周里,我一直在利用空闲时间尝试让VoteSquared.org()的Facebook身份验证工作。_和_重定向中的符号_是发生错误的位置: class OmniauthCallbacksController < Devise::OmniauthCallbacksController def facebook # You need to implement the method below in your model (e.g. app/models/user.rb)
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
#redirect_to politicians_path
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
这是一个破解的解决方案,但它似乎让我通过了这次崩溃(又一次崩溃)。我将上述代码更改为以下代码:
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user
# The following line forces confirmed_at to be set so it doesn't crash in Devise's type conversion
@user.confirmed_at = Time.now.utc
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
#redirect_to politicians_path
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
class OmniAuthCallbackController:authentication#如果未激活@user,将引发此错误
如果是导航格式,设置flash消息(:notice,:success,:kind=>“Facebook”)?
#重定向到路径
其他的
会话[“designe.facebook_data”]=request.env[“omniauth.auth”]
将\重定向到新\用户\注册\ url
结束
结束
结束
现在我将使用这个解决方案,但我希望有一个不需要手动设置值的解决方案。我认为最好让Desive做那项工作
key :confirmed_at, Time
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user
# The following line forces confirmed_at to be set so it doesn't crash in Devise's type conversion
@user.confirmed_at = Time.now.utc
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
#redirect_to politicians_path
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end