Where does business logic go in rails?

后端 未结 4 1324
借酒劲吻你
借酒劲吻你 2021-02-04 09:11

I\'m an ASP.NET MVC developer just starting with my first big project on rails however Im confused as where to put your business logic? on ASP.NET I create a library which conta

4条回答
  •  执念已碎
    2021-02-04 09:26

    Go with the concept of FatModels and SkinnyControllers. Your models should know how they behave and what they should do.

    When your models get too fat, extract them out into re-usuable modules and include them in your module.

    • Example of taking a fat controller (with logic) and moving to a model
    • Example of taking code from the views and moving into the model

    You can easily test behavior of models using RSpec (or test/unit or shoulda). Then you can test that the application behaves correctly using Cucumber.

提交回复
热议问题