Best sequence of methods for the Ruby on Rails model?

In Rails, we write a lot of code in our models, such as class methods, plugin methods, named_scopes, callbacks ... I am wondering if there is a good template for organizing the sequence. I used to see the best example in a presentation, but now I forgot.

Anyone have a suggestion? Thanks

+3
source share
3 answers

There is no path set ... If you use a scope (since Rails 3, named_scope is deprecated) that relies on a method, it must be defined after the method in the model. You can mix and match, and sometimes it needs to be done.

This does not affect boot time or performance to my knowledge.

+1

OCD , . gist .

+1

I wrote about this a while ago as part of my style guide: act_as_good_style .

YMMV as to what the "best" grouping / order is, but if you want me to take it there in the "Model Idiom" section

0
source

Source: https://habr.com/ru/post/1784404/


All Articles