ranked-model: NoMethodError undefined method `<' for nil:NilClass after 0.4.2 upgarde

I’m getting this error after upgrading from 0.4.1 -> 0.4.2. Downgrading makes it work again.

Our code:

class Tagging < ApplicationRecord
  include RankedModel

  belongs_to :tag
  belongs_to :taggable, polymorphic: true

  ranks :position, with_same: %i[taggable_id taggable_type]
end

It occurs when trying to add multiple tags in a single action, but adding them individually seems to work.

Stacktrace from Sentry: image

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 35 (19 by maintainers)

Most upvoted comments

Hi @AJMiller, thanks for the update. It’s not necessary to set a default value, you can just let the gem do that. It breaks due to our assumption that new records won’t have a rank set until they’re persisted.

You can have a null constraint on there if you like. Something went wrong if ranked-model didn’t set a rank. You can remove the default with something like this in your migration:

change_column_default :articles, :row_order, nil

https://stackoverflow.com/questions/25357171/removing-default-value-from-rails-migration