我使用的是 Rails 2.3.11
在我的views/layout/application.html.erb
<ul>
<li>1</li>
<li>2</li>
<%= myhelper('t')%>
<li>4</li>
</ul>
我正在调用myhelper
方法在application_helper.rb
中生成li
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 正在生成 .
为什么这个辅助方法没有得到。请给出建议
最佳答案
试试这个(在命名路由 users_path 之前不附加正斜杠字符):
content_tag(:li, link_to("3", users_path))
关于ruby-on-rails - 在 Rails 中使用辅助方法生成 li 标签失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5945952/