Skip to content

Instantly share code, notes, and snippets.

@kareemgrant
Created February 24, 2015 19:25
Show Gist options
  • Save kareemgrant/09ff2aed6793d0080050 to your computer and use it in GitHub Desktop.
Save kareemgrant/09ff2aed6793d0080050 to your computer and use it in GitHub Desktop.
class PostsController < ApplicationController
def index
@posts = Post.all
end
def show
@post = Post.find_by_id(params[:id])
end
def edit
@post = Post.find_by_id(params[:id])
end
def new
@post = Post.new
end
def create
@post = Post.new(params[:post])
if @post.save
redirect_to post_path(@post)
end
end
def destroy
@post = Post.find_by_id(params[:id])
@post.destroy
flash[:notice] = "This post was deleted"
redirect_to posts_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment