Created
April 12, 2012 21:44
-
-
Save patrickgombert/2371209 to your computer and use it in GitHub Desktop.
Interactor Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### We are highlighting a workflow to retrieve Employees who | |
### have the title of department leaders. | |
### The web entry point comes through the controller, | |
### but it's important for the controller to have no logic. | |
### It simply knows that it must call the department leaders | |
### method on the interactor. | |
class EmployeeController < ApplicationController | |
def get_department_leaders | |
leaders = Interactor::Employees.get_deparment_leaders | |
render 'deparment_leaders', :locals => {:leaders => leaders} | |
end | |
end | |
### Our interactor knows all about our domain. It can makes database calls, makes | |
### use of models and do all sorts of application logic that is separated from | |
### HTTP and web concerns. | |
module Interactor | |
module Employees | |
def get_department_leaders | |
Employee.where(:title => "Department Leader") | |
end | |
end | |
end | |
### The above is just an Active Record query on an existing model | |
class Employee < ActiveRecord::Base | |
### attribute :title | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment