我松散地跟随Railscast简单的OmniAuth http://railscasts.com/episodes/241-simple-omniauth创建我的Twitter登录。当我尝试通过twitter登录并创建一个新用户时,我会得到以下消息:
Validation failed: Password can't be blank, Name is not valid., Email can't be blank, Email is not valid.如果按下刷新按钮,将得到以下错误:
OAuth::Unauthorized 401 Unauthorized我已经将回调URL设置为http://127.0.0.1:3000/auth/twitter/callback,但我仍然收到该消息。我在本地主机上测试。
我把我的用户建模为Hartl的铁路http://ruby.railstutorial.org/ruby-on-rails-tutorial-book,我的网站项目要求用户填写这些字段。
与栏杆不同,我创建了一种新方法来处理杂食登录:
sessions_controller.rb
def omniauth_create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) ||
User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to user
enduser.rb
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["info"]["name"]
end
end问题:如何绕过验证?
到目前为止,我已经尝试过使用skip_before_filter :authenticate, :only => [:omniauth_create],但这不起作用。
谢谢。
发布于 2012-05-23 21:31:41
有两种方法可以跳过验证。您可以通过将:validate => false传递给create方法(通常是一个糟糕的想法)跳过它们,或者您可以将验证修改为如下所示:
user.rb
validates_confirmation_of :password, :if => :password_required?
def password_required?
!provider.blank? && super
endhttps://stackoverflow.com/questions/10728005
复制相似问题