本地一切正常,所以我将代码推送到heroku但是当我尝试使用Twitter验证用户时出现此错误。我正在使用omniauth进行身份验证。
schema.db
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.timestamp "created_at", :null => false
t.timestamp "updated_at", :null => false
t.string "password_digest"
t.string "remember_token"
t.string "image"
end
我将每个用户的个人资料图片网址拉到“图片”
下的字符串中在user.rb内部
def apply_omniauth(omniauth)
authentications.build(:provider => omniauth['provider'],
:uid => omniauth['uid'],
:token => omniauth['credentials'].token,
:secret => omniauth['credentials'].secret)
@called_omniauth = true
self.email = SecureRandom.urlsafe_base64(6)+"@testemail.com"
self.name = omniauth['info']['nickname']
self.password = self.password_confirmation = SecureRandom.urlsafe_base64(8)
self.image = omniauth['info']['image']
end
这是上面的self.image
代码行。
这是heroku日志
2013-04-15T05:11:40.520254+00:00 app[web.1]: Started GET "/auth/twitter/callback
?oauth_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&oauth_verifier=xxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx" for xx.xx.xx.xxx at 2013-04-15 05:11:40 +000
0
2013-04-15T05:11:41.177459+00:00 app[web.1]: NoMethodError (undefined method `im
age=' for #<User:0x000000073f0618>):
2013-04-15T05:11:41.177459+00:00 app[web.1]:
2013-04-15T05:11:41.177459+00:00 app[web.1]: app/models/user.rb:58:in `apply_o
mniauth'
2013-04-15T05:11:41.177459+00:00 app[web.1]: app/controllers/authentications_c
ontroller.rb:22:in `create'
2013-04-15T05:11:41.177459+00:00 app[web.1]:
2013-04-15T05:11:41.177823+00:00 app[web.1]: Processing by AuthenticationsContro
ller#create as HTML
2013-04-15T05:11:41.177823+00:00 app[web.1]: Completed 500 Internal Server Error
in 89ms
2013-04-15T05:11:41.177459+00:00 app[web.1]:
身份验证控制器
def create
omniauth = request.env['omniauth.auth']
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
user = User.find(authentication.user_id)
sign_in_and_redirect user
elsif current_user
token = omniauth['credentials']['token']
secret = omniauth['credentials']['secret']
current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'], :token => token, :secret => secret)
current_user.update_attribute(:image, omniauth['info']['image'])
sign_in_and_redirect current_user
else
user = User.new
user.apply_omniauth(omniauth)
if user.save!
sign_in_and_redirect User.find(user.id)
else
session[:omniauth] = omniauth.except('extra')
redirect_to '/signup'
end
end
end