开发者

Rails - How should one organize their model code?

I'm sorry if this seems over simplified but I'm wondering quite specifically what the general consensus is on how 开发者_Go百科model code should be organized.

Association declarations, if you think certain association types should be declared before others, accepts_nested_resource declarations, validations, custom validations, protected and private methods, module inclusions, everything and anything.

I've heard of weird gothcas that can occur with the ordering of different model callbacks and associations but have never seen them all really documented anywhere.

Obviously there will be some disagreement and there is probably not one true way but that's to be expected. I'm very curious to hear how other people organize their code. Thanks.


I use this simple three-step order:

1) Relationships 2) Validations 3) Methods

I don't think I would ever put anything after the methods or before the relationships.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜