2017-07-17 60 views
0

与空间问题,我有以下代码Rails的ERB optlabel是一种在标签

<% optgroup_label = "May 2017" %> 
<optgroup label= <%= optgroup_label %> > 

它产生以下HTML

<optgroup label="May" 2017> 

有没有其他人遇到这个问题?我不确定我错过了什么。

+0

忘记添加一些的东西。 我使用rails 4.2.0和 ruby​​ 2.3.0 –

回答

3

简单的解决了这一个,即使optgroup_label是一个字符串,你还需要将其包装在引号的HTML

<% optgroup_label = "May 2017" %> 
<optgroup label="<%= optgroup_label %>"> 

和产生<optgroup label="May 2017">而不是<optgroup label="May" 2017="">