Last active
August 29, 2015 14:04
-
-
Save thanhcuong1990/82d4b3d9abd891518888 to your computer and use it in GitHub Desktop.
Fat model & Skinny controller examples
This file contains hidden or 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
# /app/controllers/posts_controller.rb | |
class PostController < ApplicationController | |
def repost | |
post = Post.find(params[:id]) | |
if post.user == current_user | |
flash[:notice] = "Sorry, you can't repost your own posts" | |
elsif post.reposts.where(:user_id => current_user.id).present? | |
flash[:notice] = "You already reposted!" | |
else | |
# ... | |
flash[:notice] = "Succesfully reposted" | |
end | |
redirect_to post | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment