Skip to content

Instantly share code, notes, and snippets.

@rakibulislam
Created October 8, 2015 18:02
Show Gist options
  • Save rakibulislam/0652195fd87eac1a751c to your computer and use it in GitHub Desktop.
Save rakibulislam/0652195fd87eac1a751c to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
def index
@post = Post.find(params[:post_id])
@comments = @post.comments
end
def show
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])
end
def new
@post = Post.find(params[:post_id])
@comment = @post.comments.build
end
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(params[:comment])
if @comment.save
redirect_to post_comment_url(@post, @comment)
else
render :action => "new"
end
end
def edit
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])
end
def update
@post = Post.find(params[:post_id])
@comment = Comment.find(params[:id])
if @comment.update_attributes(params[:comment])
redirect_to post_comment_url(@post, @comment)
else
render :action => "edit"
end
end
def destroy
@post = Post.find(params[:post_id])
@comment = Comment.find(params[:id])
@comment.destroy
respond_to do |format|
format.html { redirect_to post_comments_path(@post) }
format.xml { head :ok }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment