Ruby on Rails: invalid nil argument type (Fixnum expected)

I get a weird error

ActionView::Template::Error (wrong argument type nil (expected Fixnum)):

In this line:

<%= (!attach.file_size.nil?) ? "(#{number_to_human_size(attach.file_size.to_i).to_s})": ""  %>

Here is my code:

<% if !pr.attachments.empty? %>
<ul class="attached_files">
  <% pr.attachments.each do |attach| %>
    <li><a href="<%= attach.path_url%> " target="_blank"><%= attach.path_identifier%></a> 
    <%= (!attach.file_size.nil?) ? "(#{number_to_human_size(attach.file_size.to_i).to_s})": ""  %>
    </li>
  <%end%>
</ul>
<% end %>

I do not understand where the problem is. Help me please. Thank!

+3
source share
1 answer

What language? If not English, try one.

It sounds the same as this error , in which the call number_to_human_sizeultimately caused BigDecimal.new(the_number.to_s).round(...).to_f, and round()ing failed due to a language problem. The excluded generation exactly matches your error ("invalid argument type nil (Fixnum expected)").

+1
source

All Articles