Day 38
Sinatra, and models, and views, and controllers, and erb, OH MY!
Sinatra, and models, and views, and controllers, and erb, OH MY! Tonight I kept building small things with Sinatra. I’ve realized exactly how the MVC system works and what each piece does. The model is all the ruby classes I’ve been writing. The view is a mixture of HTML and Ruby that the user sees in their browser. The controller takes the user input and returns the data that has been crunched by the models. Now that I’m createing the route to a URL, creating the form on that page, sending the data that’s input back to the controller, having it sent to a model, having the model return it to the controller, having the controller retrieve a new view and send it to the user, it all makes way more sense. LOL.
One thing I think will be a big piece but was only touched on for a moment was yielding.
Let’s say we have a controller action:
get '/' do erb :index end
When the above controller action is triggered and the
erb
method is called, it looks to see if there is a view titledlayout.erb
. If that file exists, it loads that content around the desired erb file, in this caseindex.erb
.
The way the layout.erb
will “wrap” the index.erb
with it’s code when a <%= yield %>
is inserted seemed like something important. Yet, I have yet to use it and I’m more than a few lessons past the reeeadme that showcased it. Oh well, that’s one of the reasons I write about things here. So when I need to find it I know where to look.
Time spent today: 2:17
Time spent total: 155:13
Lessons completed today: 6
Lessons completed total: 378
Share this post
Twitter
Facebook
LinkedIn
Email