Question

I was trying to search if I can install eruby on my windows7 machine but couldnt find anything. I could find how to install it on apache. But I want to install it on my win7 machine.

I am hoping that I can use it by embedding it in HTML, like we embed vbscript in HTML and just open the html page. Am I on the right path?

Was it helpful?

Solution

It sounds like you don't fully understand how eRuby works, so let me clarify:

When you use your web browser to open an HTML file on your computer, the web browser is reading the bytes of the file from disk, interpreting it as an HTML document, and displaying it accordingly. The web browser understands HTML (and JavaScript, and CSS).

Templating languages like ERB/eRuby/Erubis use the Ruby programming language to run arbitrary code embedded in a web page and replace the results of that code with the text it produces. This final text is sent to the web browser; the browser never sees the Ruby code, but instead sees only HTML (and JavaScript, and CSS).

For this to happen, the web browser cannot open a file from disk:
file:///C:/Users/Phrogz/Desktop/foo.erb
...but must instead request the file from a web server (like Apache):
http://localhost/test/foo
which runs the eRuby processor before sending the modified content to the browser.

You can make a very simple web server with Ruby that processes content by using a simple web framework, such as Sinatra. However, this still requires you to start the web server process on your computer before making the request.

So, in short:

No, you cannot "install eRuby on Windows 7" such that opening a file from disk with the web browser runs Ruby code.

If you need a no-server solution, you might instead look at a client-side templating language such as dust.js which runs in JavaScript on the web browser and thus can be served from the simple file: protocol.

If you can have a server, I recommend Sinatra and (instead of ERB) using Haml as your templating language.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top