title: Using Variable Values in Rails View
body: <p>I'm currently building a rails project that reaches out to PagerDuty to pull who is oncall and their contact information. I have a rails controller that contains a function like:</p>
  
  <pre><code>def findOncallInfo(arg1)
  
          primary_query = {
                  'escalation_policy_ids' =&gt; ["MY_ID"],
                  'schedule_ids' =&gt; [arg1]
          }
  
          headers = {
                  'Content-Type' =&gt; 'application/json',
                  'Accept' =&gt; 'application/vnd.pagerduty+json;version=2',
                  'Authorization' =&gt; "Token token=keklolr0flc0pt3r"
          }
  
          ocresponse = HTTParty.get(
                  'https://api.pagerduty.com/oncalls',
                  :query =&gt; primary_query,
                  :headers =&gt; headers
          )
  
          rawtext = ocresponse.body
          text = JSON.parse(rawtext)
          policies = text["oncalls"]
          policies.each do |policy|
                  oncall = policy["user"]
                  oncall.each do |key, value|
                          if key == 'id'
                                  @oncallID = value
                          elsif key == 'summary'
                                  @oncallName = value
                          end
                  end
          end
  
          inforesponse = HTTParty.get(
                  "https://api.pagerduty.com/users/#{@oncallID}/contact_methods",
                  headers: {
                          'Content-Type' =&gt; 'application/json',
                          'Accept' =&gt; 'application/vnd.pagerduty+json;version=2',
                          'Authorization' =&gt; "Token token=keklolr0flc0pt3r"
                  }
          )
  
  
          rawtext = inforesponse.body
          text = JSON.parse(rawtext)
          methods = text["contact_methods"]
          methods.each do |method|
                  if method['type'] == 'email_contact_method'
                          @oncallEmail =  method['address']
                  elsif method['type'] == 'phone_contact_method'
                          @oncallPhone = method['address']
                  end
          end
  
          @oncallfinal = [@oncallName, @oncallPhone, @oncallEmail]
  
  end
  </code></pre>
  
  <p>Now, when I call this from my view using <code>&lt;%= findOncallInfo('MY_SCHEDULE') %&gt;</code> it will return the last line of the function prior to [end]. For example, pulling up the page would display:</p>
  
  <pre><code>["My Name", "0000000000", "my.name@myemailaddress.com"]
  </code></pre>
  
  <p>Now, if I add <code>@oncallEmail</code> after <code>@oncallfinal</code> (or instead of <code>@oncallfinal</code>), it would display just the email address.</p>
  
  <p>What I'm trying to do is call all of the variables in different places on the page, but when I do so, all I receive is 'nil' on the page. For example:</p>
  
  <pre><code>&lt;h1&gt;Test&lt;/h1&gt;
  &lt;table&gt;
  &lt;%= findOncallInfo('MY_SCHEDULE_ID') %&gt; #displayed only for testing purposes
    &lt;tr&gt;
      &lt;td&gt;&lt;%= @oncallName %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= @oncallPhone %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= @oncallEmail %&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Results in:</p>
  
  <pre><code>Test
  ["My Name", "0000000000", "my.name@myemailaddress.com"]
  nil nil nil
  </code></pre>
  
  <p>Could someone give some insight into where I might be going wrong with getting these to display?</p>