title: Rails uninitialized constant error on heroku, twitter api, works fine locally
body: <p>I have a basic twitter api app in rails, which works perfectally locally, however when I pushed to Heroku it doesn't work and upon checking the logs there is an error saying <code>uninitialized constant WelcomeController::TwitterApi</code>. I can not find out how to rectify this. Many thanks.</p>
  
  <p>lib/twitter_api.rb</p>
  
  <pre><code>class TwitterApi
    def initialize(user)
      @user = user
    end
  
    def our_public_tweets
      client.user_timeline(user, count: 1, exclude_replies: true, include_rts: false)
    end
  
    def followers
      client.followers.take(20)
    end
  
    private
  
    attr_reader :user
  
    def client
      @client ||= Twitter::REST::Client.new do |config|
        config.consumer_key = Rails.application.secrets.twitter_api_key
        config.consumer_secret = Rails.application.secrets.twitter_api_secret
        config.access_token = user.token
        config.access_token_secret = user.secret
      end
    end
  end
  </code></pre>
  
  <p>application_controller.rb</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    protect_from_forgery with: :exception
  
    def current_user
      @current_user ||= User.find(session[:user_id]) if session[:user_id]
    end
  
    # to enable the current_user variable to be used in the view file
    helper_method :current_user
  
  end
  </code></pre>
  
  <p>welcome_controller.rb</p>
  
  <pre><code>class WelcomeController &lt; ApplicationController
    def index
      @twitter_api = TwitterApi.new(current_user)
    end
  end
  </code></pre>
  
  <p>views/welcome/index.html.erb</p>
  
  <pre><code>&lt;div class="wrapper"&gt;
    &lt;h1&gt;OMNIAUTH AND TWITTER API&lt;/h1&gt;
  
    &lt;!-- &lt;%= link_to "Sign in with Twitter", "/auth/twitter" %&gt; --&gt;
    &lt;% if current_user %&gt;
      &lt;div id="sign_in_wrapper"&gt;
        &lt;p id="sign_in"&gt;Signed in as &lt;span&gt;&lt;%= current_user.name %&gt;&lt;/span&gt; &lt;/p&gt;
        &lt;%= image_tag current_user.profile_image, class: "profile_image" %&gt;
        &lt;p&gt;&lt;%= link_to "Sign out", signout_path, id: "sign_out" %&gt;&lt;/p&gt;
      &lt;/div&gt;
  
      &lt;div class="public_tweets"&gt;
        &lt;p&gt;Latest tweet from &lt;%= current_user.name %&gt;:&lt;/p&gt;
        &lt;% @twitter_api.our_public_tweets.each do |tweet| %&gt;
          &lt;% cache('our_public_tweets', expires_in: 6.hours) do %&gt;
            &lt;%= parsed_tweet(tweet) %&gt;
          &lt;% end %&gt;
        &lt;% end %&gt;
      &lt;/div&gt;
  
      &lt;ul class="followers"&gt;
        &lt;p&gt;First 20 followers for &lt;%= current_user.name %&gt;:&lt;/p&gt;
        &lt;% @twitter_api.followers.each do |follower| %&gt;
          &lt;% cache('followers', expires_in: 6.hours) do %&gt;
            &lt;li&gt;&lt;%= follower.name %&gt;&lt;/li&gt;
            &lt;hr&gt;
          &lt;% end %&gt;
        &lt;% end %&gt;
      &lt;/ul&gt;
  
    &lt;% else %&gt;
  
      &lt;%= link_to "/auth/twitter", id: "link_button" do %&gt;
        &lt;i class="fa fa-twitter fa-3x"&gt;&lt;/i&gt;
      &lt;% end %&gt;
      &lt;p class="date"&gt;Click the twitter icon to sign in and view followers&lt;/p&gt;
  
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>models/user.rb</p>
  
  <pre><code>class User &lt; ApplicationRecord
    def self.from_omniauth(auth_hash)
      #Look up the user or create them using keys in the auth hash
      user = where(provider: auth_hash.provider, uid: auth_hash.uid).first_or_create
      user.update(
        name: auth_hash.info.name,
        profile_image: auth_hash.info.image,
        twitter_user_name: auth_hash.info.nickname,
        token: auth_hash.credentials.token,
        secret: auth_hash.credentials.secret
      )
      user
    end
  
    # token and secret is what came back from omniauth and this was saved to the user database.
  end
  </code></pre>
  
  <p>application_helper.rb</p>
  
  <pre><code>module ApplicationHelper
  
    def parsed_tweet(tweet)
      _parsed_tweet = tweet.text.dup
  
      tweet.urls.each do |entity|
        html_link = link_to(entity.display_url.to_s, entity.expanded_url.to_s, target: 'blank')
        _parsed_tweet.sub!(entity.url.to_s, html_link)
      end
  
      tweet.media.each do |entity|
        html_link = link_to(entity.display_url.to_s, entity.expanded_url.to_s, target: 'blank')
        _parsed_tweet.sub!(entity.url.to_s, html_link)
      end
  
      _parsed_tweet.html_safe
    end
  end
  </code></pre>