Last active
January 4, 2016 18:58
-
-
Save TalkativeTree/8663789 to your computer and use it in GitHub Desktop.
This file contains 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
class Api::PostsController < Api::Base | |
def create | |
service = PostService.new | |
service.delegate = Response.new(self) | |
service.create_new_post(params[:post]) | |
end | |
end | |
class Response < SimpleDelegator | |
def new_post_created_successfully(post) | |
render :json => post.to_json | |
end | |
def new_post_not_created_because_of(errors) | |
render :json => { | |
:errors => errors | |
}.to_json | |
end | |
end | |
#previous | |
class Api::PostsController < Api::Base | |
def create | |
service = PostService.new | |
service.delegate = self | |
service.create_new_post(params[:post]) | |
end | |
# PostServiceProtocol begins | |
def new_post_created_successfully(post) | |
render :json => post.to_json | |
end | |
def new_post_not_created_because_of(errors) | |
render :json => { | |
:errors => errors | |
}.to_json | |
end | |
# PostServiceProtocol ends | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment