I've been learning a lot about web technologies recently and I want to put together a neat little website to play with html, css, javascript, flash, and what have you.
I know that as far as the web browser is concerned all I need to do is send a text file (usually HTML) from my server using HTTP over TCP.
I've gone through a couple of Rails tutorials by now but I am having a lot of trouble getting things to work and understanding how the components work together even if I could get it to work by blindly following said tutorials to the letter.
I think I understand the MVC concept. Obviously the business model of an application makes sense to be kept separate from the view implementation, etc. Sure, that's fine. From what I understand RoR needs (?) a database. Sure, when my website grows to a point where I need to track customers and crunch data, I will want that.
But where do I get at the actual functionality? Where do I specify how my server responds to requests from browsers? Shouldn't this be straightforward? Do I need to set up a database just to get my "hello world" page up?
I think what might be happening is that Rails is designed to do something that I don't need (yet?). It does many things for me that I don't understand, and in order for me to be comfortable I would have to dig through a lot of material to figure it out.
What brought me to this point is, I am looking for the "next step" after this little server I was playing with:
require 'socket'
server = TCPServer.open(8080)
loop {
Thread.start(server.accept) do |client|
client.puts(Time.now.ctime) # server sends dynamic page consisting of current time
client.flush
while (str = client.gets) do
puts "recvd >> "+str # show what server gets from client
if str.chop.length == 0 then break end # detect end of transmission
end
puts "done"
client.close
end
}
This little bit of code is more than halfway there to what I need it to do. I got stuck on something pretty silly. I still don't know how to just take a file on disk and send it to the client. I figure i'd open a stream to the requested file and pipe it over to the socket... No idea how to do that in ruby. So I figured, hey, maybe Rails'll do it for me.
Now I follow a bunch of directions, finally get the server running on mongrel, and I try this: ruby script\generate controller MyTest
and still get a "Routing Error" when I open it up in the browser. I get a giant ugly stack trace on the cmdline. Screw this!
Clearly I should be taking a class that will show me how to use Rails and more importantly, whether or not it is overkill for my purposes. So... should I keep trying to figure it out? If so, can someone show me a good tutorial, or explain to me why the tutorials I have seen aren't helping me?
Should I just try to use EventMachine to make my server? I just want to make a nice simple fast web server.
Thanks for reading. :)