我正在使用rails 2.3.11
在我的views/layout/application.html.erb
<ul>
<li>1</li>
<li>2</li>
<%= myhelper('t')%>
<li>4</li>
</ul>
我正在调用myhelper
方法在li
application_helper.rb
def myhelper(v)
if v
content_tag(:li, link_to("3",/users_path))
end
end
我已确认myhelper
被调用,但它不会生成li
标记。
请提出建议。
修改
我正在尝试根据从同一个应用程序助手中的一个辅助方法收到的值来生成li标签,这是一个集合
def myhelper(v)
collections.each_with_index do |c,i|
case c
when 'c'
content_tag(:li, link_to("3", users_path))
end
end
end
def collections
@enabled ||= Setting.get_enabled
end
其中collections是从同一帮助程序 - 应用程序帮助程序
中的另一个辅助方法接收的数组当我评论以下两行
时 collections.each_with_index do |c,i|
end
li正在产生。
为什么这个辅助方法没有得到。请给出建议
答案 0 :(得分:4)
尝试此操作(在命名路径users_path之前没有附加正斜杠字符):
content_tag(:li, link_to("3", users_path))