I have a question about tags in .html.erb files.
Which practice is better: 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 ones instead? How to decide?
Using the Rails tag helpers will occur a pretty big overhead cost compared to simply writing a html tag in ERB (or Haml or Slim). This is usually an acceptable tradeoff for readablity and productivity when working with "dynamic html" (in the sense of markup created with server-side input) but is totally unnecessary if there is no interpolation going on.
Basically just use common sense - the Rails tag helpers (and all their derivatives such as the form helpers) are not meant as a total replacement for writing HTML in your views but rather as utilities to make it easier and cleaner to bind variables to the attributes and content of tags. They also make it much easier to write your own helper methods where you programatically create HTML instead of using string concatenation.
TLDR; Using both where applicable is the best practice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With