質問

How can I run .erb files in the browser? It is not in the Rails framework so I can't run in terminal the "rails server" command.

It is like a customized directory with .erb files.

This is the directory structure:

enter image description here

Do I need a webserver to run it like WEBrick for me to see it in localhost? How can I access it?

Thanks.

役に立ちましたか?

解決

Are you using a different Ruby framework or need to access server data? If not, you can generate HTML from erb with the command line, then simply open the HTML:

<% # page.erb %>
<html>
  <head>
    <title>My erb</title>
  </head>
  <body>
    <h1>it is: <%= Time.now %></h1>
  </body>
</html>

To compile and open from the command line:

$ erb page.erb > page.html
$ open page.html 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top