Ryan Litwiller Ryan Litwiller - 1 year ago 153
Ruby Question

Use a variables in ruby gem dasing.io - dashboard .erb files - sinatra

Working with dashing.io to make some awesome dashboards. I understand that dashing was build with ruby and sinatra and uses .erb files in a specific directory to make dashboards.

I have no issues setting up dashing or getting info into my dashboards with the .erb jobs.

What I'm trying to do is use a variable passed from the uri string in one of my dashboard .erb files. The dashboard directory also has a layout.erb file that looks like the template and this is what I'm trying to put:

<% group = params["apps"] %>

However this gives me an error in sinatra. Ideally I'd like to add a uri parameter to change the dashboard. So I'd like to hit my instance of dashing running at
add a uri parameter

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="<% group %>" data-view="List" </div>

and use that to dynamically create my erb file as such:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="group1" data-view="List" </div>

I started looking at erb layouts on sinatras docs but with so many different technologies meshed together here, I'm not sure the order of how the page is built and at what point or file I would need to make these changes.


I thought I was making some progress, I forked the gem and altered this line in the app.rb file:

get '/:dashboard/' do


get '/:dashboard/group/' do

which allows me to use this in my dashboards to get the url parameter
<%= params[:group] %>
but this seems to break the dashboards. Gridster still shows the widget boxes but no data. This seems to be breaking the
from being resolvable, as I'm getting a resource not found.

Answer Source

The answer to this was much simpler then trying meddle with the dashing gem, and was very close to my original attempts. Thanks to nauoa65 at fiverr!

This is what I needed in my dashboard's erb, this answer is on the sample.erb dashboard.

<!-- The parameter should come from http://sample.com:3030/sample?apps=mytestparam -->
<% group = params[:apps] || "A default value if parameter is not set" %>

<!-- The equal sign outputs the content of variable to html -->
<%= group %>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download