You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Talk
Why can I call this
<td><%= team.players.sum(:misses) %></td>
and this
<td><%= team.players.sum(:misses) %></td>
but this gives me 0 (some do not have 0 for misses)
<td><%= team.players.sum(:hit) /
team.players.sum(:misses) unless team.players.sum(:misses) == 0 %></
td>
Craig Demyanovich
unread,
Apr 14, 2008, 10:13:38 AM4/14/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
Say hits = 2 and misses = 4. In Ruby, 2/4 = 0. However, 2.0/4.0 = 0.5. Try those expressions in irb.
To solve your problem, you could convert the numbers to floats: hits.to_f / misses.to_f = 2.0 / 4.0 = 0.5.