Skip to content

Instantly share code, notes, and snippets.

@thanhcuong1990
Last active August 29, 2015 14:04
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 thanhcuong1990/82d4b3d9abd891518888 to your computer and use it in GitHub Desktop.
Save thanhcuong1990/82d4b3d9abd891518888 to your computer and use it in GitHub Desktop.
Fat model & Skinny controller examples
# /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