Ruby sort by (integer) "comparison of NilClass with 3200 failed"

ruby, ruby-on-rails, sorting

Solution

How about to try convert nil to integer?

   @ebms = Ebm.all
   @ebms.sort_by! { |u| u.number.to_i }

Problem

I want to sort my records in an rails application: ``` @ebms = Ebm.all @ebms.sort_by! {|u| u.number} ``` The `u.number` is defined as integer! The problem is that Rails cannot compare it with `nil`: ``` comparison of NilClass with 32400 failed ``` What can i do to evade this error?

Original source

Related problems