On Wed, Dec 8, 2010 at 10:23 PM, Jesse J. [email protected]
wrote:
that can be done with just Ruby, or would I be better off to learn Ruby
on Rails?
Any tutorials, tips, or links would be greatly appreciated.
-JRJurman
–
Posted via http://www.ruby-forum.com/.
It sounds like you just want a static site (content doesn’t change),
with
simple pages that you serve up to the user? If so, the simplest way to
do it
is just write it with HTML.
A step up from there would be to generate the pages with ERB, this would
allow you to do some calculations in the page at the time you compile
them
to HTML. For example:
require ‘erb’
template = <<-HTML
<% ('a'..'z').each do |char| %>
- <%= char %>
<% end %>
HTML
puts ERB.new(template,nil,'>').result
A step up from there would be to go to a static site framework, here is
a
pretty good list:
A step up from there would be a simple dynamic website, probably with a
database. I’d suggest Sinatra, and the Sinatra screencast from Peepcode
shows a good example.
And of course, you’ll need to host it somewhere. Heroku is fast and easy
for
this sort of thing (though you need to know git – or at least how to
add ,
commit , and push) For a static site, you will want this hierarchy:
|-- config.ru
-- public |-- file1.html
– index.html
Where “public” contains your static html files that you want to serve
up,
and “config.ru” has the contents:
run lambda { |env|
if env[‘PATH_INFO’] == ‘/’
[301, { ‘Location’ => ‘/index.html’ , ‘Content-Type’ => ‘text/html’
},
[‘’] ]
else
Rack::File.new(File.dirname(FILE)+“/public”).call(env)
end
}
Final thoughts: I’m going to recommend against serving Sinatra on
Heroku,
you have to know what you’re doing and be able to go digging through
their
source code to troubleshoot errors stemming from not using Rails. For
that,
you might look into Engine Y., I haven’t used them, but they
repeatedly
impress me, and are supposed to be willing to work with you if you need
it.
If your site is more than trivially dynamic, I think Rails is better
than
Sinatra. I worked on a moderately sized Sinatra project where quite a
bit of
time was spent dealing with not having the niceties of Rails accessible.
If this is your first dynamic site, and you are debating between Sinatra
and
Rails, go with Sinatra. You will be overwhelmed with Rails, but Sinatra
is
pretty easy to grok. It also will get you comfortable enough with the
concepts that Rails will be much easier for you afterward.