Ruby on Rails tags and HTML tags

I have a question about tags in .html.erb files.

Which is the best practice: Ruby on Rails tags or HTML tags? Is it better to use Ruby on Rails tags as much as possible? Or maybe I should avoid them and choose HTML instead? How to solve?

+3


source to share


1 answer


Using the Rails tag helpers will have quite a lot of overhead compared to just writing an html tag in ERB (or Haml or Slim). This is usually an acceptable trade-off for readability and performance when working with "dynamic html" (in the sense of markup generated with server-side input), but is completely unnecessary if there is no interpolation.

Mostly just common sense - Rails tag helpers (and all their derivatives such as form helpers) are not meant to be a complete replacement for writing HTML in your views, but rather as utilities that make it easy and simple to bind variables to attributes and tag content. They also make it easy to create your own helper methods where you create HTML programmatically instead of using string concatenation.



TL; DR; Using best practice where applicable

+3


source







All Articles