English 中文(简体)
简单 OmniAuth-Twitter 由于验证未能创建新用户
原标题:Simple OmniAuth-Twitter failing to create new user because of validation

我顺着铁路播客简单 OmniAuth http://railscasts.com/episods/241-simple-omniauth 创建我的推特登录。当我试图通过推特签名并创建新用户时,我收到以下信息:

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.00. 1:30/auth/twitter/twitter/callback 上,但我仍然收到这个信息。 我在本地主机上测试 。

我以Hartl的轨迹研究http://ruby.railstruction.org/ruby-on-rails-tumental-book 为我的用户模拟了我的用户,我的网站项目要求用户填满这些域。

与铁路播客不同, 我发明了一个新的方法处理 omniauth登录:

控制线.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
end

用户.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_filter:audeticate, : only {gt;}[:omniauth_create] ,但是这行不通。

谢谢

最佳回答

跳过验证有两个方法可以跳过。 您可以跳过它们, 将 < code>: validate {gt; 假的 转到创建方法( 通常为 A bad Idea ), 或者您可以修改验证方法如下 :

用户.rb

validates_confirmation_of :password, :if => :password_required?

def password_required?
  !provider.blank? && super
end
问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签