In rails, whether to use form helpers or not to?

前端 未结 5 1005
天命终不由人
天命终不由人 2021-01-05 12:18

In rails, is it recommended to use form helpers? Internally, everything boils down to plain html then why not write the html directly? Performance will obviously be better i

5条回答
  •  被撕碎了的回忆
    2021-01-05 13:05

    This is a very old question but I am a newbee on rails. I would argue that instead of writing this

    
    
    

    writing the same thing with rails helpers like this

    <%= label_tag 'email', nil, class: 'input-group__label' %>
    <%= email_field_tag "email", nil, placeholder: "e.g. me@something.com", class: "input-group__field" %>
    

    in a form_tag is a very DRY way of doing things. Readability is better in the first one. Everybody can understand it. No rails knowledge is required. Rails specific tags are not evaluated and converted (slight performance increase). Amount of code is the same. If that was inside a form_for which creates form from a model, I understand the use of rails specific tags and helpers. It makes sense. But I don't see a real advantage of using rails helpers for simple html as in the example above.

提交回复
热议问题