Ruby

Joshua Woods
Joshua Woods
2,007 Points

Why is there more than than one ERB file?

Why did we create a second ERB file?

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 23,731 Points

I'm not exactly sure what you are referring to here, but yes, a Sinatra app will often have multiple ERB files associated with it-- each ERB file is a "view"

ERB, which you already know means "Embedded Ruby" and is similar to other templating languages in web frameworks like Flask's Jinja2 and Django's template language which combine HTML and a context-aware subset of the programming language.

Typically, each "view" will have an ERB file which contains a mixture of HTML and embedded Ruby code. Ruby and ERB are so flexible that you could easily have two or more ERB files associated with a view. For example, depending on a user login type you could show either a "normal user template" or an "administrator template"

Another way to use multiple ERB files is to use the "sub-templating" approach. Where one ERB file will include a second ERB file.

https://www.ruby-forum.com/t/subtemplating-with-erb/121510

Joshua Woods
Joshua Woods
2,007 Points

WOW thanks for letting me know!