Skip to content

Instantly share code, notes, and snippets.

@TalkativeTree
Last active January 4, 2016 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TalkativeTree/8663789 to your computer and use it in GitHub Desktop.
Save TalkativeTree/8663789 to your computer and use it in GitHub Desktop.
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