将字符串标记为HTML安全 [英] Marking a string as HTML safe
问题描述
我正在尝试构建我的第一个Rails应用程序,并且正在使用 Ryan Heath的navigation_helper 插件提供导航中的当前课程.我建立了我的命名路由,如下所示:
I am trying to build my first Rails application and I'm using Ryan Heath's navigation_helper plugin to give me the current class in my navigation. I built my named routes as follows:
match 'games' => 'games#index', :as => :games
match 'new' => 'games#new', :as => :new
match 'previous' => 'games#previous', :as => :previous
match 'settings' => 'settings#index', :as => :settings
然后在我的application_layout中添加以下代码
Then in my application_layout I added the following code
<%= navigation([:games, :new, :previous, :settings]).html_safe %>
根据我对Rails的了解,html_safe应该强制HTML正确呈现,但是我得到的却是:
From what I know of Rails the html_safe should force HTML to be rendered properly, but instead what I get is this:
<ul class="navigation">["<li class=\"current\"><a href=\"/games\">Games</a></li>", "<li class=\"\"><a href=\"/new\">New</a></li>", "<li class=\"\"><a href=\"/previous\">Previous</a></li>", "<li class=\"\"><a href=\"/settings\">Settings</a></li>"]</ul>
那么我是在做错什么,还是插件做错了?我知道该插件是在2.x天内写回的,这与我对HTML的处理方式有所不同,但我还不够了解.
So am I doing something wrong or is the plugin doing something wrong? I know that the plugin was written back in 2.x days which from what I know handled HTML a bit differently, but I just don't know enough.
推荐答案
https://github.com com/priceflex/navigation_helper/commit/ad7bf45db1845e9299e9da39cf214866b608dd47 尝试对rails3使用此前叉修复问题
https://github.com/priceflex/navigation_helper/commit/ad7bf45db1845e9299e9da39cf214866b608dd47 try to use this fork wich fix issues for rails3
这篇关于将字符串标记为HTML安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!