Rails ERB<%-...-%>与<%...%>
问题描述:
因此,对于ERB文件,<%之间有什么区别-...-%>与<%...%>?据我所知,它们的作用相同,但是一个需要比另一个更多。
So for an ERB file, what's the difference between <%- ... -%> vs. <% ... %>? As far as I can tell, they serve the same purpose but one requires more typing than the other.
答
使用破折号可以删除在ERB标签周围的空白处,有一个 RailsCast 对此进行了讨论其他查看技巧。
Using the dash removes the whitespace around the ERB tag, there is a RailsCast that talks about this and some other View tricks.