Mayur Randive
Mayur Randive

Reputation: 643

Performance difference between plain HTML and Rails/ERB helper templates

I am new to rails and trying to understand this concept, as there are many things which we write using helpers(erb/rails tags) can also be written using simple plain html , is there any other advantage to using rails/erb helper than enabling to write more simple and readable code.

As the end result of writing the erb/rails template is always going to be a plain html , so initially by writing plain html do we reduce load on server or reduce servers efforts of converting the rails/erb templates into plain html.

Note: I am specifically asking for more of static templates e.g web forms , links , form contents,etc.

Upvotes: 2

Views: 618

Answers (1)

Ryo
Ryo

Reputation: 2123

Here're some of merits.

Ability to Collaborate with models and helpers

It automatically generates post url and form labels etc. So, say you're changing the name of a model or url, if you were writing plain html for all templates, you'll have to manually replace all of occurrences on your own, whereas the "rails-way" can handle them all just with one line of modification or one command execution.

Can take advantage of template libraries.

There're lots of awesome template libraries that generate html from ruby code.

https://github.com/plataformatec/simple_form

https://github.com/justinfrench/formtastic

Gives you better abstraction

It gives you good abstraction in the way that it makes you write what you want instead of how you do. For example in my previous project, I was using bootstrap2 and decided to move to bootstrap3. If I were writing plain html, I had to see all html files, and inspect sometimes intricately structured html tags, classes, and find all bootstrap2 specific elements and change them all. But thanks to the template generation gem I was using, all I had to do was basically to upgrade the gem and add a few lines to some config files.

Upvotes: 3

Related Questions