この問題の解決策が何日も見つかりませんでした。私は Ruby on Rails の初心者なので、明らかな何かが欠けていると確信しています。
新しいイベントごとに作成したいツイートにリンクするために、Web サイトの URL を短縮しようとしています。サイトで新しいイベントを作成すると、次のエラーが表示されます。
NameError: 未定義のローカル変数またはメソッド
bitly' for main:Object from (irb):7 from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in
start' from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/commands/console.rb:8:instart' from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/commands.rb:41:in
' from script/rails:6:inrequire' from script/rails:6:in
'
bitly gemを使用しています。
私の宝石ファイルには、次のものがあります。
gem 'bitly', "~> 0.9.0"
config/initializers に bitly.rb ファイルを作成しました。
Bitly.configure do |config|
config.api_version = 3
config.login = "xxxx"
config.api_key = "yyyy"
end
私のイベントモデルには、次のものがあります。
after_create :tweet_event
def tweet_event
client = Bitly.client
u = bitly.shorten('http://www.weinevents.de')
u = u.short_url
tweet = title + " " + u
send_tweet(tweet)
end
私の application_helper.rb ファイルには、次のものがあります。
def send_tweet(tweet)
client = Twitter::Client.new
client.update(tweet)
end
そして、私のapplication_controllerには
require 'bitly'