How do I use to_sentence for links?

something like that:

John will send a message to user1, user2, user3 and user4

this does not work

@users.collect{ |u| link_to(u.name, user_path(u)) }.to_sentence

      

+2


source to share


3 answers


ez,

link_to

in Erector goes straight to the output stream. You need to either replace to_sentence

or attack the behavior of link_to, or replace link_to. Since link_to is simple in this context, I would recommend the following:



  rawtext users.map { |u|
      "<a href='#{user_path(u)}'>#{u.name}</a>"
  }.to_sentence

      

+2


source


Odd...

@users.collect{ |u| link_to(u.name, user_path(u)) }.to_sentence

      

and



@users.map{ |u| link_to(u.name, user_path(u)) }.to_sentence

      

Must work. What error are you getting?

+3


source


Make sure you actually print the results with <%= ... %>

, I know I sometimes forget the equal sign and spend a lot of time trying to figure out what's going on.

0


source







All Articles