Brien
August 19, 2007, 12:05am
#1
Hey all, I’m trying to get a link_to to display a link to the number
of comments for a post.
I can get the number + text with
pluralize post.comments.count, ‘Comment’
but I can’t seem to do
<%= link_to pluralize post.comments.count, ‘Comment’, :action =>
‘show’, :id => post, :anchor => ‘comments’ %>
What would be the best way to do this?
Brien
August 19, 2007, 12:13am
#2
This is what you are after:
<% link_text = “#{post.comments.count} #{pluralize(post.comments.count,
‘Comment’)}” -%>
<%= link_to link_text, :action => ‘show’, :id => post, :anchor =>
‘comments’ %>
If you nest function calls, you need to parenthesize the inner calls.
Brien wrote:
‘show’, :id => post, :anchor => ‘comments’ %>
What would be the best way to do this?
–
Sincerely,
William P.
http://www.billpratt.net
[email protected]
Brien
August 19, 2007, 12:17am
#3
Hi –
On Sat, 18 Aug 2007, Brien wrote:
<%= link_to pluralize post.comments.count, ‘Comment’, :action =>
‘show’, :id => post, :anchor => ‘comments’ %>
What would be the best way to do this?
Putting the arguments to pluralize in parentheses should do it:
<%= link_to pluralize(post.comments.count, ‘Comment’), :action =>
‘show’, :id => post, :anchor => ‘comments’ %>
David
–
Brien
August 19, 2007, 12:20am
#4
Hi –
On Sat, 18 Aug 2007, William P. wrote:
This is what you are after:
<% link_text = “#{post.comments.count} #{pluralize(post.comments.count,
‘Comment’)}” -%>
That’s going to give you the number twice (10 10 Comments), since
pluralize already puts the number in. You just need to put the
arguments to pluralize in parentheses (see my other post).
David
–
Brien
August 19, 2007, 12:23am
#5
Correct, sorry 'bout that.
[email protected] wrote:
That’s going to give you the number twice (10 10 Comments), since
pluralize already puts the number in. You just need to put the
arguments to pluralize in parentheses (see my other post).
David
–
Sincerely,
William P.
http://www.billpratt.net
[email protected]