class TwitterProfile < ActiveRecord::Base
def send_status_update(status_update)
if publish?
client = Twitter::Client.new(:oauth_token => authentication.token,
:oauth_token_secret => authentication.secret)
client.update(status_update.to_twitter_string)
end
rescue Exception => e
logger.info "Error publishing to twitter: #{e.to_s}"
end
end
有一個StatusUpdate模型和一個觀察者將它們轉發到after_create
中的Twitter。我有時出現以下情況例外:Ruby NameError undefined本地變量或方法`e
NameError (undefined local variable or method `e' for #<TwitterProfile:0x00000004e44ab8>):
app/models/twitter_profile.rb:23:in `rescue in send_status_update'
app/models/twitter_profile.rb:18:in `send_status_update'
app/models/status_update_observer.rb:6:in `block in after_create'
app/models/status_update_observer.rb:4:in `after_create'
app/models/workout_observer.rb:5:in `after_update'
app/controllers/frames_controller.rb:76:in `update'
app/controllers/application_controller.rb:24:in `call'
app/controllers/application_controller.rb:24:in `block (2 levels) in <class:ApplicationController>'
app/controllers/application_controller.rb:10:in `block in <class:ApplicationController>'
缺少什麼我在這裏?
這很奇怪,但很有趣,它看起來像'=> e'的行爲不存在。 –
注意:不要搶救'Exception' - rescue'StandardError'。見http://www.thattommyhall.com/2011/02/24/rescue-exception-harmful-signals-in-ruby/ – zetetic