Rails ERb best practices (<% %> vs <% -%> vs <%- -%>)

What is the recommended use of ERb in Rails when it comes to <% %> (evaluate Ruby code), <% -%> (evaluate Ruby code, suppress the trailing newline) and <%- -%> (evaluate Ruby code, suppress the trailing newline and leading space)? It seems like <%- -%> would make the output HTML look nicest, but <% %> seems to be mostly what I see.


It's a personal preference. I use <% %> when I'm writing a loop or a block, because I want new lines there. I use <% -%> in rare cases of variable assignment. And I never use <%- -%> because that's one option too many.

Need Your Help

ASP.NET: Code behind or no code behind?

.net asp.net asp.net-3.5 separation-of-concerns

Why would anyone want to not use a code behind file so that server sided code is separated from markup? Wasn't that supposed to be one of the advantages of .NET over classic ASP?

Android Back End Technology - Language (Java, Python) & IDE (CoderBuddy, exo Cloud, Cloud 9)

java android python ide cloud

I've done my research and narrowed this down. OK, so I am deciding on the language and and tool to use for backend (server side) of developing cloud based android applications.. I've decided on G...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.