Rails content_tag 导航生成器助手
抱歉,如果这听起来很明显,但我很困惑。 我正在尝试构建一个导航列表助手。
目前,它从数组接收链接列表。
module ApplicationHelper
def site_pages
%w{index about contact promotions}
end
def nav_builder list
list.map do |l|
content_tag :li do
content_tag :a, :href => "#{l}_path" do
l
end
end
end
end
end
但是当我运行该页面时,它会将页面中的所有内容输出为数组。
[<li><a href="index_path">index</a></li> <li><a href="about_path">about</a></li> <li><a href="contact_path">contact</a></li> <li><a href="promotions_path">promotions</a></li>]
而不是显示链接列表。 有什么特别要做的吗?
==编辑==
我这样称呼我的构建者:
<%= nav_builder site_pages %>
Sorry if this sounds obvious but i'm getting confused.
I'm trying to build a navigation list helper.
At the moment it receives a list of links from an array.
module ApplicationHelper
def site_pages
%w{index about contact promotions}
end
def nav_builder list
list.map do |l|
content_tag :li do
content_tag :a, :href => "#{l}_path" do
l
end
end
end
end
end
But when I run the page it ouput everything is the page as an array.
[<li><a href="index_path">index</a></li> <li><a href="about_path">about</a></li> <li><a href="contact_path">contact</a></li> <li><a href="promotions_path">promotions</a></li>]
instead of displaying a list of links.
Is there anything special to do?
==EDIT==
I call my builder this way:
<%= nav_builder site_pages %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该帮助程序应返回 HTML 字符串,而不是数组。尝试将数组元素连接到单个字符串中:
The helper is expected to return a String of HTML, rather than an Array. Try joining the Array elements into a single String: