Skip to content

Instantly share code, notes, and snippets.

@andrzejkrzywda
Created August 8, 2014 11:18
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 andrzejkrzywda/f3f57cd415c0ea0f34c5 to your computer and use it in GitHub Desktop.
Save andrzejkrzywda/f3f57cd415c0ea0f34c5 to your computer and use it in GitHub Desktop.
def create
begin
PublishBlogPost.new.call(post_id)
rescue BlogPostNotFound
redirect_to foo
rescue AlreadyPublished
flash[:error] = already_plublished_message
render :foo
end
end
class PublishBlogPost
takes :db
def call(post_id)
post = db.find_post(post_id)
raise BlogPostNotFound if post.nil?
raise AlreadyPublished if post.published?
post.publish!
db.save(post)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment