Here is an example:

require 'erb'
require 'sqlite3'

template = ERB.new <<"END_OF_TEMPLATE"
<html>
<head>
<title><%= name %></title>
<style type="text/css">
 div {color:blue;}
</style>
</head>
<body>
<div>Name: <%= name %></div>
<div>Color: <%= color %></div>
</body>
</html>
END_OF_TEMPLATE

db = SQLite3::Database.new( "my_db.db" )
table = "test"


db.execute( "select * from #{table}" ) do |row|
  name, color = row

  File.open("#{name}.html", "w") do |f|
    f.puts template.result(binding)
    #binding gathers up the variables and their values

  end

end

--output:--

hammer.html:

<html>
<head>
<title>hammer</title>
<style type="text/css">
 div {color:blue;}
</style>
</head>
<body>
<div>Name: hammer</div>
<div>Color: black</div>
</body>
</html>

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to