Updating view.html.erb with response from REST API

I have an app that starts a server. When it starts the server, it sends a message to a separate REST API on server B. Server B then sends a json message back.

{
"status": "success",
"url": "https://...."
}

I want to show that url in view.html.erb so the user can see it. I’ve seen a few posts about how this could be done in before.sh.erb but at least with how I’m currently setting it up, it makes sense to me to run it in script.sh.erb. I could write it to a file and then output the contents of that file?

I think I’ve seen people show the content of output.log but I can’t find any of those at the moment. Anyone have any ideas?

Hey!

Here are a few examples off the top of my head that do similar things:

Lastly (and my least favorite way to do it), the “multitenant-instruction” app in my Multitenant Apps will produce a card that renders a markdown file. It will display any changes to the file each time it gets re-rendered in the dashboard. It’s easy to do. This was what I did to display the animated Deacon gifs during my presentation.

3 Likes

That got me to where I needed to be! Thanks Sean!!

If anyone comes across this in the future with the same question, here’s what I ended up doing:

$ touch template/url.txt
$ cat view.html.erb
<%= File.read(url_file) %>
$ head -5 submit.yml.erb
---
batch_connect:
  template: "basic"
  conn_params:
    - url_file
$ cat template/before.sh.erb
#!/bin/bash
export url_file=$(pwd)/url.txt
$ cat template/script.sh.erb
echo "your content" > ${url_file}
1 Like