Created
October 8, 2015 18:02
-
-
Save rakibulislam/0652195fd87eac1a751c to your computer and use it in GitHub Desktop.
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
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