title: in rails, how do i access json from my d3 js code?
body: <p>I'm trying to use <strong>d3-rails</strong> gem to use d3.js in my rails app. </p>
  
  <p>I included both</p>
  
  <pre><code>gem "d3-rails"
  gem "d3js-rails"
  </code></pre>
  
  <p>in my <strong>Gemfile</strong>.</p>
  
  <p>The problem is, right now I have a index.html.erb page that just prints json (which I don't have, it's from a <strong>third party api db</strong>) in text format (without use of any d3). In place of the text format, I want some bar charts enabled by d3.js. I'm still pretty new to rails, so I'm quite confused.</p>
  
  <ol>
  <li><p>Right now I have access to a specific json value, say </p>
  
  <p>@parsed_data</p></li>
  </ol>
  
  <p>and say that json contains the following data. Oh first of all, that json name -- @parsed_data -- I was able to successfully access through ruby language portion of my erb file, but how do I do the same in javascript for the sake of d3?</p>
  
  <pre><code>{
    "firstName": "John",
    "lastName": "Smith",
    "age": 25,
    "address": {
      "streetAddress": "21 2nd Street",
      "city": "New York",
      "state": "NY",
      "postalCode": "10021"
    },
    "phoneNumber": [
      {
        "type": "home",
        "number": "212 555-1234"
      },
      {
        "type": "fax",
        "number": "646 555-4567"
      }
    ],
    "gender": {
      "type": "male"
    }
  }
  </code></pre>
  
  <p>Knowing the structure of this JSON (but I don't have it sitting somewhere in my asset pipeline, it's from third party API), how would I use d3 in my current index.html.erb? </p>
  
  <p>Do I need a separate javascript file for this? Can I embed it in my existing View file (index.html.erb) with script tag? </p>
  
  <p>p.s. How I'm displaying the fetched JSON in text has nothing to do with d3. It just uses ruby language to parse through the JSON. </p>
  
  <p>Here is the tutorial I tried to follow but without success. 
  <a href="http://www.overfitted.com/blog/?p=302" rel="nofollow">http://www.overfitted.com/blog/?p=302</a></p>
  
  <p>Also other stackoverflow posts, but I'm not sure if I really need AJAX for this task. Wouldn't using a d3js-rails / d3-rails gem suffice? Also new to AJAX (crash-coursed through a few pages of reading, but still confused) so excuse me if I am saying something that might sound silly. </p>
  
  <p>p.s.s. I have the following in my application.js. </p>
  
  <pre><code>//= require_tree
  //= require d3
  </code></pre>