Hello, I''m just starting out with RoR and have been playing around with making my own blog using RoR as a quick way of getting my feet wet. RoR is neat isn''t it! Liking the link_to etc helpers, seems such a good way of doing things. Anyway, my little problem goes like this: I want a link that says Comments (#of comments), for instance "Comments (2)". To make my link without the number, I have used: <%= link_to ''Comments'', {:action => ''show'', :id => post, :anchor => ''comments''}, :class => ''comments'' %> And I know that: <%= post.comments.count %> tells me how many comments are for this post. (I''m looping through a load, so the :id exists etc.) How do I do this? <%= link_to ''Comments (post.comments.count)'', {:action => ''show'', :id => post, :anchor => ''comments''}, :class => ''comments'' %> so that the code actually executes? I can''t work it out! Thanks! -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
On 23 Dec 2007, at 19:26, Richard Brashaw wrote:> > How do I do this? > > <%= link_to ''Comments (post.comments.count)'', {:action => > ''show'', :id => > post, :anchor => ''comments''}, :class => ''comments'' %> >If you have a string delimited with double quotes (or equivalent) you can embed bits of ruby with #{}, for example "Hello #{person.name}" Fred> so that the code actually executes? I can''t work it out! > > Thanks! > -- > Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Richard Brashaw wrote:> How do I do this? > > <%= link_to ''Comments (post.comments.count)'', {:action => ''show'', :id => > post, :anchor => ''comments''}, :class => ''comments'' %> > > so that the code actually executes? I can''t work it out! > > Thanks!For all ruby code, you can execute ruby is a string like so: "Comments #{post.comments.count}" #=> Comments 3 Note the double quotes, single quote string will not allow this. You can also just use +, alhtough #{} is generally cleaner. ''Comments '' + post.comments.count.to_s -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 23 Dec 2007, at 19:26, Richard Brashaw wrote: > >> >> How do I do this? >> >> <%= link_to ''Comments (post.comments.count)'', {:action => >> ''show'', :id => >> post, :anchor => ''comments''}, :class => ''comments'' %> >> > If you have a string delimited with double quotes (or equivalent) you > can embed bits of ruby with #{}, for example > "Hello #{person.name}" > > FredThank you so much! I remember seeing that before somewhere now! -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---