In Grouper, we are long-term users Rails, like other agile teams RapGenius and Kickstarter as in New York. It is easy to use and can Nike Free Run Womens effectively improve the efficiency of the developer. However, people began to notice Nike Air Max Air Jordan Outlet its shortcomings - when more than a few thousand lines of code, test suites will become slow and frame loading time will increase significantly. Some did not help the Rails feature to encourage users to use less design patterns, which usually results in highly coupled code, and the slow unmaintainable test suite. We realize that there is no need to have to do so. Rails is perhaps the most perfect tool for agile Mens Nike Free 3.0 Wool Skin Shoes Blue Yellow development, but for medium or large program it is not the most effective. We solve these problems by three criteria, we believe that these concepts can be part of any high-level rails of development, they are: Interactors, Policies, Presents. The first part - Interactors Air Max 2011 Womens Grey Green Black popular trend now is in rails code in ActiveRecord's `models` folder, most of the business logic code in a huge class. This usually implies that a class has a lot of responsibility, a huge public API, and a method only in order to achieve the object of the complex relationship functions. One important factor is the ActiveRecord callbacks; `before_save` hook function to modify the status of other objects in a class. This is a serious problem, because before processing the object of our concern must get all of these other objects. During the test, it will become very slow (because these objects are usually obtained from the database), the callback function and method of implementation of the long call chain also makes this process becomes difficult. The solution is 'Interactors' criteria (usually called 'Service Objects'). Interactors requirements of core applications are stored in a series of pure ruby object, save the main application logic, making ActiveRecord class as data persistence interface layer. View Interactors by name, you can Mens Nike Free 3.0 Wool Skin Shoes Blue Yellow clearly understand the application functions; Mens Nike Free 3.0 V2 Shoes White Black Red for example, `SignUp`,` BookGrouper`, `AssignBarForGrouper` like. Other classes, like `Member` and` Bar` just to validate Nike Air Max 95 Men and save the properties, such as name, location and date. (As a background - organizer organization named 'Groupers' of activities, 3 on 3 drink in the bar, which is a very interesting activity.) Interactor is a lightweight gem, providing a range of convenient method, such as `success`, `failure`, so your controller looks like this: class GroupersController \u0026 lt; ApplicationController :: Base ... def create interactor = ConfirmGrouper.perform (leader: current_member)?? if interactor.success redirect_to home_path? else 2015 Nike Free 5.0 flash [: error] = interactor.message render: new end end ... end your Interactor looks like this: # Responsible for creating a Grouper, email ## class 535807 103 Jordan CP3.VI White Black Game Royal Sport Red CP3 Shoes 2013 Sale ConfirmGrouper include Interactor def perform grouper = Grouper.new (leader: member ) fail (grouper.errors.full_messages) unless grouper.save send_emails_for (grouper) assign_bar_for (grouper) end private def send_emails_for (grouper) LeaderMailer.grouper_confirmed (member:! grouper.leader.id) .deliver WingMailer.grouper_confirmed (wings: grouper .wings.map (\u0026 amp;: id).) deliver AdminMailer.grouper_confirmed (grouper: grouper.admin.id) .deliver end def assign_bar_for (grouper) # Asynchronous job because it's a little slow AssignBarForGrouper.enqueue (grouper.id) endend This way is Air Max 2011 Men Blue Black a lot of merit, but in the complexity of the code and test speed. For example, your test now will be significantly accelerated, because you almost Mens Nike Free 3.0 Wool Skin Shoes Blue do not need to read the database, and you can go independently test each ActiveRecord model without the need to worry about its relevance. Interactors can use the virtual objects (doubles) not to use ActiveRecord model (models), while the test suite is not even necessary to Mens Nike Free 3.0 Wool Skin Shoes Blue Yellow load the Rails. Test your controller looks Mens Nike Free 3.0 Wool Skin Shoes Blue like this: describe GroupersController do ... describe '#create' do subject {post: create} before {ConfirmGrouper.stub (: perform) .and_return (interactor)} let (: interactor) {double ( 'Interactor', success ?: success, message: 'foo')} context 'when the interactor is a success' do let (: success) {true} it {should redirect_to home_path} end context 'when the interactor fails' do let (: success) {false} it {should render: new} end endend are carried through all the stub ActiveRecord database calls, test run time from about 4,5 seconds before dropped to about 0.15 seconds. In addition, this will make your applications become more straightforward, since each class will have a separate action, for example, `Bar` class knows the location of the bar and its opening hours. It does not need to know `Grouper`, about which one will be assigned` Bar` which `Grouper` complex safety logic stored in the` AssignBarForGrouper`Interactor in. Finally, if you keep Interactors short and has a single purpose, you can combine multiple Interactors complete more complex logic. This way you can mix and match effectively reduce the coupling of your code, and allows you to reuse operations when necessary. Summary Obviously, you need to choose the Air Max 2011 Womens Blue Black right way to solve the problem you are experiencing, not a universal model to solve all the problems, the guidelines mentioned above and perhaps 15 minutes in a blog quickly build applications that do not Suitable. We are opposed to Rails to build it as an entry application for beginners, and is recommended for all situations the same way. Once the code became complicated, you will be the way to solve the problem you are not sure. We recommend using Interactors as a problem-solving approach. The next part of this series, Policy Objects can simplify the controller. If you are interested in best practice design patterns Rails, please pay attention to our position, we are hiring. You can also get some inspiration on hacker news.Rails missing part (1): Interactors