2011-12-28 117 views
0

我試過使用 ,但它不斷添加雙引號,導致HTML頁面在我的html中直接打印出 。下面是我的示例代碼:在haml中填充選擇標籤

helper.rb

def available_options 
    ["test1   | test222 ", "test1   | test222 ", "test1   | test222 "] 
end 

在我看來:

= f.select, options_for_select(available_options) 

有沒有辦法適當地渲染這件事情?我試過raw和html_safe無濟於事。

回答

2

html_safe應該在這裏做的伎倆,請在您的helper.rb試試這個

def available_options 
    ["test1   | test222 ", 
    "test1   | test222 ", 
    "test1   | test222 "].map(&:html_safe) 
end 
+0

實際上,html_safe是罪魁禍首,因爲它變成我的 到& NBSP; – corroded 2011-12-28 07:40:54

+0

嗯爲我工作正是這個例子..無論如何,檢查[本頁](http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/),可能它會幫助你 – alony 2011-12-28 07:53:23

+0

@alony:在這裏上網http://chat.stackoverflow.com/rooms/5676/ruby-rails-enterprise-apps-developers – 2011-12-28 08:18:20