I´m looking for a way to do simple ruby code without rails. I´m coming from PHP world, and sometimes, I just build a page with a Mysql connection, run a query and show resul
The simplest way I know of is to use Ruby's CGI module, and run the script as CGI. Depending on your performance requirements and complexity of the page you want to generate, something like this might just do the trick:
#!/usr/bin/ruby
require 'cgi'
require 'mysql'
con = Mysql.new("localhost","user","pass","mydb")
rs = con.query('select * from users')
cgi = CGI.new('html4')
cgi.out {
cgi.html {
cgi.body {
rs.each_hash { |row| puts #{"row['name']} - #{row['age']}" }
}
}
}
You would want to consider the overhead of establishing connection to MySQL on each request, and for complex pages you will need a templating mechanism.