Views and Models

Learn about views and models of our Rails application.

We'll cover the following...

Views

Rails support for rendering HTML web views is quite sophisticated and powerful. In particular, the coupling between the Active Model and Rails’ form helpers is very tight (a great example of the power in tightly coupling components). Actions performed by boundary classes that result in dynamic output (usually controllers and mailers) will initiate the rendering of the view from a template, and that template may pull in JavaScript, CSS, or other templates (partials).

Often, the templates are HTML, but they can be pretty much anything, including JSON, text, or XML. Templates also have access to helpers, which are free functions in the global namespace. Rails provides many helpers by default, and we can make our own.

Press + to interact

View code tends to feel messy because while a particular template can be isolated pretty well, including decomposing it into reusable partials, CSS and JavaScript, by their nature, aren’t organized in the same way. Often, CSS and JavaScript are globally available, and taking care to keep them isolated can be tricky.

Rails 7 includes what DHHDavid Heinemeier Hansson ...