0

I want to get value of my variable(ruby array) dynamically in erb file. I am able to call the value in erb page, but as my job keeps running and the value of the variable keeps changing and I want its changes to be reflected on my erb file.

1 Answers1

0

I hope you are enjoying your Dashing experience so far.

The idea of Dashing is that any events and most dynamic content would be processed/generated in the client (the browser). The backend knows how to get data, the frontend knows how to show it.

You need to make the client side CoffeeScript reflect the changes that are sent to the dashboard. So, your Ruby job should send an array of widget data -- each element representing one widget.

Then you loop over the data and initialise it in your widget.

Batman.js provides view-bindings that can loop over data [1]:

<li data-foreach-item="items"><div class="my-awesome-widget></div></li>

You can also loop over it in the CoffeeScript onData method:

onData: (data) ->
  $.forEach data, (widget) =>
    @makeMyWidget widget

If you want to hide a widget based on the data, you can do this in your onData:

// Ruby Job
send_event('event', { data: the_data, hidden: true })

// Widget CoffeeScript
onData: (data) =>
  if(data.hidden)
    $(@node).hide();
tylermauthe
  • 488
  • 4
  • 13
  • For example I have two widgets, one showing temperature in a line graph widget and another showing other data using meter widget . Next time the job runs, i get only one widget showing temperature in a line graph widget . I'd like to hide the other meter widget. How to achieve this? – Savitha Ks Aug 28 '15 at 10:15
  • I am not sure that I'm clear on what you're asking, but I've added an example that shows how to hide a widget. Basically, the data you send in `send_event` needs to include some meta-data about what layout to use (the layout options in this case being, both shown and one hidden). – tylermauthe Aug 28 '15 at 21:23