title: Using environment variables in controller (Rails)
body: <p>I'm trying to display SendGrid email statistics inside my Rails application.</p>
  
  <p>So far, I've been able to display them in API's return format (e.g. <code>[{"delivered"=&gt;9, "unsubscribes"=&gt;0, "repeat_bounces"=&gt;2,....</code>), but <strong>that's only if I put the plaintext username and password into my controller's private method</strong> because I cannot seem to use <code>'SENDGRID_USERNAME'</code> and the <code>'SENDGRID_PASSWORD'</code> environment variables. What's a guy to do?</p>
  
  <p>In summation: </p>
  
  <p><strong>NewslettersController:</strong></p>
  
  <pre><code>  before_action :set_client, only: :index
  
  private
  
      def set_client
        @client = SendGridWebApi::Client.new('the plaintext username', 'the plaintext password')
      end
  </code></pre>
  
  <p><strong>Newsletters Index View</strong></p>
  
  <pre><code>&lt;p&gt;&lt;%= @client.stats.get %&gt;&lt;/p&gt;
  </code></pre>
  
  <p>Is there another place where I can set <code>@client</code> where my view can get to it and my plaintext password can be hidden from the outside world? preferably a place I can put in <code>secrets.yml</code>?</p>
  
  <pre><code>@client = SendGridWebApi::Client.new('SENDGRID_USERNAME', 'SENDGRID_PASSWORD')
  </code></pre>
  
  <p>Returns an incorrect username and password, even though I got the plaintext username and password I'm using for testing <em>from those variables</em>, so I know that they're set to the correct ones.</p>
  
  <p>Or, is there a way to use environment variables in either my controller or my view?</p>
  
  <p>I'm able to set the variables in the Rails Console and then use them, but since they don't get saved I can't access them afterwords in my actual application.</p>