Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
What is a Form Builder?1:12 with Jason Seifer
We've used forms several times while building out our Rails application. Now let's learn a little bit about what's going on behind the scenes when we create a form using the form_for method.
By now we've created a few forms in our Rails app.
Behind the scenes though, Rails is doing quite a bit to get everything working.
When we call the form_for method,
Rails is automatically creating something called a form builder for us.
The form builder is responsible for taking the object that we're using, for
example, a to-do list, and generating the HTML that we see when we
call something like text field on the to-do list title.
If we were in the edit view, the form builder would also fill in the value for
the title and can even apply different HTML if there are errors.
With Ruby on Rails you're not limited to just the default form builder
and its styling.
It's actually pretty easy to create your own and save yourself a lot of typing or
generate your own markup that works with your app's design.
We're going to use the concept of class inheritance to write our own form builder.
This sounds intimidating, but it's actually nothing to be scared of.
All it means is that we're going to have the ability to call the existing form
builder classes and methods, like text field, when we write our own form builder.
You need to sign up for Treehouse in order to download course files.Sign up