user2980621
user2980621

Reputation: 1

Configuring Twitter Gem with Ruby on Rails

I am trying to do a simple rails app that will search Twitter. I am using the Twitter gem (http://sferik.github.io/twitter/). I created a twitter_credentials.rb in the initializer folder with following code:

require 'twitter'

Twitter::REST::Client.new do |config|
  config.consumer_key = ENV['TWITTER_CONSUMER']
  config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
  config.access_token = ENV['TWITTER_ACCESS_TOKEN']
  config.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
end

My view looks like this:

<% Twitter.search("to:justinbieber marry me",
   :result_type => "recent").take(3).each do |tweet| %>
  <%= tweet.text %>
<% end %>

However, whenever I try to call any method from the docs, I get an error "undefined method method name for Twitter:Module". I've also tried moving that block into the appropriate controller but I receive the same error. Any help would be really appreciated..

Upvotes: 0

Views: 148

Answers (1)

kaleb4eg
kaleb4eg

Reputation: 2564

I faced with same issue. But I have installed two gems https://github.com/sferik/twitter and https://github.com/twitter/twitter-text-rb, they both have 'Twitter' as main module and when I call Twitter, I reached second instead first...

Upvotes: 1

Related Questions