【发布时间】:2014-07-27 03:09:56
【问题描述】:
使用 twitter api 创建应用程序,我有相关代码 但是当我想使用 figaro gem 来保护时,我在输入 rake figaro:heroku 时出现错误
rake figaro:heroku
rake aborted!
NoMethodError: undefined method `reject' for #<String:0x007ff074af1010>
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/figaro-0.7.0/lib/figaro.rb:39:in `flatten'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/figaro-0.7.0/lib/figaro.rb:17:in `env'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/figaro-0.7.0/lib/figaro/railtie.rb:7:in `block in <class:Railtie>'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:36:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:44:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.4/lib/rails/application.rb:67:in `inherited'
/Users/neilpatel/Desktop/Rails/tweetscope/config/application.rb:10:in `<module:Tweetscope>'
/Users/neilpatel/Desktop/Rails/tweetscope/config/application.rb:9:in `<top (required)>'
/Users/neilpatel/Desktop/Rails/tweetscope/Rakefile:4:in `<top (required)>'
keyword.rb 文件
def grab_twitts
client = Twitter::REST::Client.new do |config|
config.consumer_key = "2DZcdTw4p1m2yU18xxxxxxxxx"
config.consumer_secret = <%= ENV["CONFIG.CONSUMER_SECRET"] %>
config.access_token = "71875314-xPOGuWIU7CiDcR3Vx9xxxxxxxxxxxxxxxx"
config.access_token_secret = <%= ENV["CONFIG.ACCESS_TOKEN_SECRET"] %>
end
安装了 figaro gem 并将以下信息添加到 application.yml
CONFIG.CONSUMER_SECRET = "whpCvjNmePXzj6iSfxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
CONFIG.ACCESS_TOKEN_SECRET = "1P00CJmiQ7Tqhxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
删除 = 后:现在又出现错误
Users/neilpatel/Desktop/Rails/tweetscope/app/models/keyword.rb:10:语法错误,意外的 tCONSTANT,期待关键字_end ...g.access_token_secret:' /Users/neilpatel/Desktop/Rails/tweetscope/app/models/keyword。 rb:34: 语法错误,意外的输入结束,期待关键字结束
class Keyword < ActiveRecord::Base
has_many :tweets
def grab_twitts
client = Twitter::REST::Client.new do |config|
config.consumer_key "2DZcdTw4pvccccccccccccc"
config.consumer_secret <%= ENV["CONFIG.CONSUMER_SECRET"] %>
config.access_token "71875314-xPOGuWIU7CiDcR3Vx9pkJbbbbbbbbbbbbb"
config.access_token_secret: <%= ENV["CONFIG.ACCESS_TOKEN_SECRET"] %>
end
client.search(self.word, :count => 10, :result_type => "recent").take(10).collect do |tweet|
new_tweet = Tweet.new
new_tweet.tweet_id = tweet.id.to_s
new_tweet.tweet_created_at = tweet.created_at
new_tweet.text = tweet.text
new_tweet.user_uid = tweet.user.id
new_tweet.user_name = tweet.user.name
new_tweet.user_screen_name = tweet.user.screen_name
new_tweet.user_image_url = tweet.user.profile_image_url.to_s
new_tweet.keyword = self
new_tweet.save
end
end
end
【问题讨论】:
-
您是否尝试过按照SO answer 中的建议在
application.yml中使用:而不是=? -
是的,现在出现新错误
标签: ruby-on-rails ruby heroku