简体   繁体   中英

Ruby sort_by with null values

Using Ruby on Rails. I'm trying to sort a query by number (saved as string) and letter. However, my letter column can contain "NULL" values. This crashes when there are Null values in the letter column:

@fences = Fence.find(:all,
                     :conditions => ["coursewalk_id = #{@coursewalk.id}"]).sort_by { |a| [+(a.number.to_i), a.letter] }

How can I fix this?

a.letter.to_s应该做的伎俩。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM