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.
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();