I'm trying to integrate twitter feed into my rails four 4 app, a cms for that matter. I settled of twitter gem and had it successfully installed. I set up the following in application_controller.rb.
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
require 'twitter'
@client = Twitter::REST::Client.new do |config|
config.consumer_key = 'my consumer key'
config.consumer_secret = 'my consumer secret'
config.access_token = 'access token'
config.access_token_secret = 'access token secret'
end
end
Note: I've omitted my credentials here but have them correctly in my app. Then I added the following in my views i.e application.html.erb
<section id="tweets">
<ul>
<% @client.each do |tweet| %>
<li><%= tweet.text %></li>
<% end %>
</ul>
</section>
I get the following error
undefined method `each' for nil:NilClass
What could I be doing wrong? I've read through the twitter gem documentation, started off by setting up an initializer, realized my local variable in the initializer lost scope by the time I was in the views so I deleted it and added the initialization in the controller. Note it's @client
A detailed answer would be appreciated.