syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
How do I read JSON into HAML?

Let HAML do the talking:
%h1 Chart
:ruby
  myjson=''
  jsonf = "#{Rails.root}/app/views/pred_lr/chart.json"
  File.open(jsonf,'r'){|cj|cj.each_line{|aline| myjson <<aline}}
:javascript
  var jsjson = #{myjson}

Here is the resulting HTML:

<h1>Chart</h1>
<script>
var jsjson =  [{"unixtime":1417392000,"closing_price":2053.44},{"unixtime":1417478400,"closing_price":2066.55}]
</script>


syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me