2011-12-28 70 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