Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (38 sloc) 1.06 KB
class CommentsController < ApplicationController
def index
@article = Article.find(params[:article_id])
@comments = @article.comments
end
def new
@article = Article.find(params[:article_id])
@comment = @article.comments.build
end
def create
@article = Article.find(params[:article_id])
@comment = @article.comments.build(params[:comment])
if @comment.save
flash[:notice] = "Successfully created comment."
redirect_to article_url(@comment.article_id)
else
render :action => 'new'
end
end
def edit
@comment = Comment.find(params[:id])
end
def update
@comment = Comment.find(params[:id])
if @comment.update_attributes(params[:comment])
flash[:notice] = "Successfully updated comment."
redirect_to article_url(@comment.article_id)
else
render :action => 'edit'
end
end
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
flash[:notice] = "Successfully destroyed comment."
redirect_to article_url(@comment.article_id)
end
end