Skip to content

Commit 9112869

Browse files
author
Lee Richmond
committed
Add example customizing persistence
1 parent a2aced4 commit 9112869

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

app/resources/employee_resource.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,30 @@ class EmployeeResource < ApplicationResource
66
scope: -> { Position.all },
77
foreign_key: :employee_id,
88
resource: PositionResource
9+
10+
def create(attributes)
11+
employee = Employee.create(attributes)
12+
log('Created', employee)
13+
employee
14+
end
15+
16+
def update(attributes)
17+
employee = Employee.find(attributes[:id])
18+
employee.update_attributes(attributes.except(:id))
19+
log('Updated', employee)
20+
employee
21+
end
22+
23+
def destroy(id)
24+
employee = Employee.find(id)
25+
employee.destroy
26+
log('Deleted', employee)
27+
employee
28+
end
29+
30+
private
31+
32+
def log(prefix, employee)
33+
Rails.logger.info "#{prefix} #{employee.first_name} Employee via API"
34+
end
935
end

0 commit comments

Comments
 (0)