Reputation: 3245
What would be the closest thing to having Ruby in HTML like for PHP with <?php ?>
tags?
Can it be done without the need of frameworks that impose website structure or without the need to run Ruby servers, ecc... ?
Is there a way?
Upvotes: 5
Views: 649
Reputation: 3245
Rack middleware and application for serving dynamic pages in very simple way. There are no controllers or models, just only views like a jsp, asp and php!
https://github.com/migrs/rack-server-pages
https://stackoverflow.com/a/32938202/988591
You can run it with "rackup" or any app server supporting rack. For example with passenger you just need to go to the folder where config.ru is and run "passenger start".
Upvotes: 2
Reputation: 119
You can cram as much logic in a template as you wish, but you still need an application server. PHP has this as mod_php or through FastCGI, etc. Ruby offers many options. Consider serve or create a bare bones sinatra app.
Consider what ends you are trying to achieve. This is generally poor practice and many people moved from the old style PHP to more modern frameworks which avoid this pitfall. This may be why only 2 people use it and you can't find any tutorials.
Upvotes: 1
Reputation: 6930
You're looking for erb files.
Open a test.erb
file and write this down:
<h1><%= "hello" %></h1>
then run it with:
ruby -rerb -e 'puts ERB.new(File.read("test.erb")).result'
To run erb within a webser you need to wrap it somehow.
Here is a gem that does the job:
Serve - A Rapid Prototyping Framework for Web Applications
gem install serve
And then run it on the directory where your scripts are:
serve
The standard address is localhost:4000
Upvotes: 1