brendon / ranked-model

An acts_as_sortable/acts_as_list replacement built for Rails 4+
https://github.com/mixonic/ranked-model
MIT License
1.09k stars 134 forks source link

{column_name}_rank causes NoMethodError #171

Closed balajivenkatesh closed 3 years ago

balajivenkatesh commented 3 years ago

According to the Readme,

If you need to find the rank of an item with respect to other ranked items, you can use the {column_name}_rank method on the model instance. {column_name} is your resource ranking column.

But invoking {column_name}_rank causes NoMethodError . Though {column_name}_position works. Is that expected?

Looking at https://github.com/mixonic/ranked-model/commit/200ebe2e5cf283219022688f733d78c79df2fa71#diff-0101443cdd715634c1e9e26e4460f27662129d8d8afbc994447f3d5ffbbde998R68 seems to suggest the {column_name}_rank may not be public?

[Edit] My gem version was 0.4.2 and the latest is 0.4.6 I updated with bundle update ranked-model and this was fixed.

brendon commented 3 years ago

Hi @balajivenkatesh, the public method is defined here:

https://github.com/mixonic/ranked-model/blob/master/lib/ranked-model.rb#L64

Are you calling this on the base model object?

balajivenkatesh commented 3 years ago

@brendon thanks for the quick response!

My gem version was 0.4.2 and the latest is 0.4.6 I updated with bundle update ranked-model and the method is available now. Closing issue.

brendon commented 3 years ago

Oh sorry, I see what you mean. Looks like we may have forgot to declare that method public :) Would you like to do a PR fixing this, along with a test for it?

I just see your new message now, are you sure it's working? It looks like we're defining it in the private area still.

brendon commented 3 years ago

I'm guessing this line is probably not really necessary anymore? https://github.com/mixonic/ranked-model/blob/master/lib/ranked-model.rb#L68

balajivenkatesh commented 3 years ago

Yes, that line might not be necessary anymore - define_method doesn't explicitly say it but it might be the case. https://stackoverflow.com/questions/3782026/how-do-i-dynamically-define-a-method-as-private says how private dynamic methods can be specified

brendon commented 3 years ago

Thanks @balajivenkatesh