ez.
ez.

Reputation: 7654

how to use to_sentence for links?

some thing like this:

John 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

Upvotes: 4

Views: 1560

Answers (3)

ndp
ndp

Reputation: 21996

ez,

link_to in Erector goes right to the output stream. You either need to replace to_sentence, patch into link_to's behavior, or replace link_to. As link_to in this context is simple, I'd recommend that:

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

Upvotes: 2

Michael Sepcot
Michael Sepcot

Reputation: 11385

Make sure you are actually printing out the results with <%= ... %>, I know I sometimes forget the equal sign and spend a lot of time trying to figure things out.

Upvotes: 0

manalang
manalang

Reputation: 805

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

Should work. What error are you getting?

Upvotes: 4

Related Questions