使用复杂的条件

不好的

1234567891011121314151617

# app/controllers/posts_controller.rbclassPostsController<ApplicationControllerdefdestroypost=Post.find(params[:id])ifpost.enabled?&&(user.own_post?(post)||user.admin?)post.destroymessage="Post destroyed."elsemessage="You're not allow to destroy this post."endredirect_toposts_path,notice:messageendend

# app/controllers/posts_controller.rbclassPostsController<ApplicationControllerdefdestroypost=Post.find(params[:id])ifuser.can_destroy_post?(post)post.destroymessage="Post destroyed."elsemessage="You're not allow to destroy this post."endredirect_toposts_path,notice:messageendend