我使用的是以CMS为模板的CMS网站,我需要对这些页面应用跳过导航。
因此在他们绘制的默认模板中,我有以下内容:
<a href="#some-content">Skip to Some Content</a>
<a href="#other-content">Skip to Other Content</a>
<a href="#yes-content">Skip to Yes Content</a>
然后在CMS中,我将ID应用于内容
<div id="some-content">Stuff</div>
我要尝试的是仅在该页面上实际使用锚标记时。
因此,例如,如果我在“其他内容”页面上,则不会显示所有锚标签。
我的想法是以下帮助者:
module ApplicationHelper
def current_url(url)
url = request.path_info
if url.include?('other')
content_tag :a, href: '#other-content'
end
end
end
然后我将锚标签替换为
<%= current_url %>
And ... ActionView :: Template :: Error(错误的参数数量(给定0,应为1))
我的助手有问题吗?
我也在助手中尝试了以下相同的结果:
def original_url
base_url + original_fullpath
end
def anchor_update
if original_url.include?('services')
content_tag :a, href: '#services'
end
end
答案 0 :(得分:1)
ActionView :: Template :: Error(错误的参数数量(给定0, 预期1))
好吧,current_url(url)
期望一个参数,而您将其称为<%= current_url %>
没有任何参数,这会导致该错误。从外观上看,应该在为url
显式进行分配时定义没有任何参数的方法。
module ApplicationHelper
def current_url
url = request.path_info
if url.include?('other')
content_tag :a, href: '#other-content'
end
end
end
答案 1 :(得分:0)
您在<%= current_url %>
中缺少参数,它应该看起来像<%= current_url(url) %>