Hi,
I want to display the number of comments for a post in a link_to. So
the link will look like below.
Comments(3)
How do i build this string in the link_to. I get an error about trying
to convert a fixnum to a string see code below.
<% case post.comments.size
when 0 %>
<p>No Comments</p>
<% else %>
<P><%= link_to ''Comments('' +
post.comments.size + '')'', :action
=> ''show'', :id => post %></P>
<% end %>
On another note. Would it be better to seperate this code into a
controller returning a string saying No Comments/Comments(x) incase i
needed it in more than 1 place?
--
Posted via http://www.ruby-forum.com/.
Rimantas Liubertas
2006-Apr-02 11:37 UTC
[Rails] Custom built link_to display text problem
<...>> I want to display the number of comments for a post in a link_to. So > the link will look like below.<...>> How do i build this string in the link_to. I get an error about trying > to convert a fixnum to a string see code below. > > <% case post.comments.size > when 0 %> > <p>No Comments</p> > <% else %> > <P><%= link_to ''Comments('' + post.comments.size + '')'', :action > => ''show'', :id => post %></P> > <% end %>How about this: <P><%= link_to (post.comments.size> 0)?"Comments(#{post.comments.size})":''No comments'', :action => ''show'', :id => post %></P> Regards, Rimantas -- http://rimantas.com/