Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails content_tag helper for simple things?

Should I be using the content_tag helper for all html tags when working with Rails?

Is it The Rails Way to use content_tag for even simple things like Header tags?

<%= content_tag :h2, :class => "bla bla" do %>
  Header
<% end %>

vs.

<h2>Header</h2>

Clearly just using straight html is much 'simpler' and 'shorter', but what is the correct Rails Way of doing things?

like image 657
ardavis Avatar asked Dec 04 '22 21:12

ardavis


1 Answers

Using content_tag when you don't have to is a waste. There's no need to use ERBisms to generate static HTML so don't do it. If some other piece of code determines what tag to use, then you'd use content_tag to construct that tag.

like image 172
mu is too short Avatar answered Dec 27 '22 05:12

mu is too short