有些事情是这样的:
John向user1,user2,user3和user4发送消息
这不起作用
@users.collect{ |u| link_to(u.name, user_path(u)) }.to_sentence
答案 0 :(得分:4)
...奇
@users.collect{ |u| link_to(u.name, user_path(u)) }.to_sentence
和
@users.map{ |u| link_to(u.name, user_path(u)) }.to_sentence
应该有效。你得到什么错误?
答案 1 :(得分:2)
EZ,
Erector中的 link_to
直接进入输出流。您需要替换to_sentence
,修补link_to的行为,或者替换link_to。由于此上下文中的link_to很简单,我建议:
rawtext users.map { |u|
"<a href='#{user_path(u)}'>#{u.name}</a>"
}.to_sentence
答案 2 :(得分:0)
确保您实际上使用<%= ... %>
打印出结果,我知道我有时会忘记等号并花费大量时间来解决问题。