I need to execute a ruby script from within my view. It's a script
that dynamically generates an image as output, so the invocation
should look something like this:
<%= image_tag "/images/myScript.rb?args=foobar"%>
Now I don't know how to configure WEBrick to execut the ruby file when
I put it in my project folder in public/images and access it through
When doing so, my browser displays the source of myScript.rb instead
of executing it.
Another possibility would certainly be to run my script as a webserver
on a different port and invoking it like this:
<%= image_tag "localhost:3001/myScript.rb?args=foobar"%>
but a second server running seems to be a little bit of overkill to
I'd apreciate any suggestions. If there is any better way to do this,
please let me know.
Thanks a lot,
You could use rails and call your script from a controller then render it :
render :text => result_from_script
render :inline => result_from_script
thanks for the quick reply.
this approach may insert some external HTML or whatever into my final
output to the browser, but I cannot embed the image like this, right?
The idea is to invoke the script from the client and produce a HTML
response followed by the image data. The reason for this is because
the image is not saved as a file (for performance), so I have to
directly send it to the client after computation.
I have just discovered the "send_data" method which seems to do
exactly what I need: send a string containing binary data to the
client. It even lets me specify the content type, so it's perfect for
I'll try it out and let you know if it worked out.
it worked out pefectly. I created an additional controller that solely
returns the image using send_data() instead of rendering any template.
thanks for your help.