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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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:> 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? > > > > >-- Sincerely, William Pratt http://www.billpratt.net billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-18 22:16 UTC
Re: link_to - naming issue
Hi -- On Sat, 18 Aug 2007, Brien wrote:> > 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?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) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-18 22:19 UTC
Re: link_to - naming issue
Hi -- On Sat, 18 Aug 2007, William Pratt 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) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Correct, sorry ''bout that. dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org wrote:> Hi -- > > On Sat, 18 Aug 2007, William Pratt 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 > >-- Sincerely, William Pratt http://www.billpratt.net billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---