# Link\_to - naming issue

**URL:** <https://www.ruby-forum.com/t/link-to-naming-issue/112439>\
**Category:** Rails\
**Created:** [August 19, 2007, 12:05am UTC](https://www.ruby-forum.com/t/link-to-naming-issue/112439 "2007-08-19T00:05:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a6a055/32.png) [@Brien](https://www.ruby-forum.com/u/Brien)\
**Post date:** [August 19, 2007, 12:05am UTC](https://www.ruby-forum.com/t/link-to-naming-issue/112439/1 "2007-08-19T00:05:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Brien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a6a055/32.png) [@Brien](https://www.ruby-forum.com/u/Brien)\
**Post date:** [August 19, 2007, 12:13am UTC](https://www.ruby-forum.com/t/link-to-naming-issue/112439/2 "2007-08-19T00:13:12Z")

</div>

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](http://www.billpratt.net)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Brien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a6a055/32.png) [@Brien](https://www.ruby-forum.com/u/Brien)\
**Post date:** [August 19, 2007, 12:17am UTC](https://www.ruby-forum.com/t/link-to-naming-issue/112439/3 "2007-08-19T00:17:12Z")

</div>

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

–

- Books:  
RAILS ROUTING (new! [http://www.awprofessional.com/title/0321509242](http://www.awprofessional.com/title/0321509242))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![Brien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a6a055/32.png) [@Brien](https://www.ruby-forum.com/u/Brien)\
**Post date:** [August 19, 2007, 12:20am UTC](https://www.ruby-forum.com/t/link-to-naming-issue/112439/4 "2007-08-19T00:20:12Z")

</div>

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

–

- Books:  
RAILS ROUTING (new! [http://www.awprofessional.com/title/0321509242](http://www.awprofessional.com/title/0321509242))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![Brien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a6a055/32.png) [@Brien](https://www.ruby-forum.com/u/Brien)\
**Post date:** [August 19, 2007, 12:23am UTC](https://www.ruby-forum.com/t/link-to-naming-issue/112439/5 "2007-08-19T00:23:13Z")

</div>

Correct, sorry 'bout that.

removed\_email\_address@domain.invalid 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](http://www.billpratt.net)  
removed\_email\_address@domain.invalid
