I'm working on a web-app without a framework right now, and I'm trying to structure it as a MVC app. The problem is, there are some technical aspects of MVC apps that escape me.
Primarily, how should a view be build? I'd like to use a markup language like eRuby or #haml, but I don't know how exactly they work and how to implement them in a non-Rails application.
How does the view get data from the model and directions from the controller? In Rails, this is all obfuscated. How can I implement this? What's the theory behind this? Do I make a connection to my database in the view and then use it freely there? Do I have it pass through another program aside from just the #haml renderer to give it data?
Thanks!
I don't yet have enough points to comment but to answer your question on cwninja's answer, in most cases you render the view form within a controller action. A controller gets a request, executes the right action and return's a response, in this case a rendered view as the response body. A simple example using haml could look like this:
class SomeController
def some_action
@foo = "bar"
Haml::Engine.new(template).render(self)
end
end
In this case instance variables setup in the controller will automatically be made available to the view since they are defined in the same context. Variables from the model will not be available as they shouldn't, however anything you can access from the controller action can be accessed from the view. Most templating systems also allow you to pass along a hash of local variables to the view, eg:
Haml::Engine.new(template).render(self, {:foo => "bar"})
I hope this clears up some of your confusion :)