Rails 中的业务逻辑在哪里? [英] Where does business logic go in rails?

查看:52
本文介绍了Rails 中的业务逻辑在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名 ASP.NET MVC 开发人员,刚刚开始我在 Rails 上的第一个大项目,但是我对将业务逻辑放在哪里感到困惑?在 ASP.NET 上,我创建了一个库,其中包含处理业务逻辑的服务(域驱动设计),我听说 Rails 使用了胖模型瘦控制器的概念,但是我在 ASP.NET 中有一些项目将所有逻辑添加到控制器会弄得一团糟,还有其他办法吗?

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 contains services(Domain driven design) which handle business logic, I have heard that rails uses a concept of fat model skinny controller but I have some projects in ASP.NET which adding all the logic to the controller would create a big mess, is there any other way?

推荐答案

采用 FatModels 和 SkinnyControllers 的概念.您的模型应该知道它们的行为方式以及它们应该做什么.

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.

您可以使用 RSpec(或 test/unit 或 shoulda)轻松测试模型的行为.然后,您可以使用 Cucumber 测试应用程序的行为是否正确.

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.

这篇关于Rails 中的业务逻辑在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆