2011-03-12 36 views
0

我在使用軌道形式的ruby中使用& -notation時遇到問題。看一下:以滑軌形式轉義字符

<% form_for(@object) do |f| %> 
    <%= f.select :field, [['option 1', 1], [' option 1.1', 2]] %> 
<% end %> 

正如你所看到的,選項1.1應該在前面有兩個空格,它應該在下拉列表中看起來縮進。作爲HTML,這不起作用,我應該使用& nbsp ;.我如何在這種情況下做到這一點?

回答

1

如果你的目標是隻直觀地顯示縮進,使用CSS,並設置相關的選項類:

<%= f.select :field, [['option 1', 1], ['option 1.1', 2, { :class=>'indent_level_1' }]] %> 

<style> 
    .indent_level_1 
    { 
    color:red; /*just for testing whether the class got applied or not.*/ 
    margin-left:1em; 
    } 
</style> 

如果&nbsp;應該是文本的一部分(我猜不是?),然後你可以使用raw():

<%= f.select :field, [['option 1', 1], [raw('&nbsp;&nbsp;option 1.1', 2)]] %> 

Ps。 「& -notation」的正確名稱是「HTML字符實體引用」

+0

我不認爲CSS適用於下拉列表,是嗎?然而,使用'raw()'的解決方案對我來說工作得很好,謝謝! – 2011-03-12 19:22:18

+0

具體來說,CSS * does *爲'