Skip to content

Instantly share code, notes, and snippets.

@pawellenart
Created June 18, 2011 18:13
Show Gist options
  • Save pawellenart/1033356 to your computer and use it in GitHub Desktop.
Save pawellenart/1033356 to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
before_filter :load_project
before_filter :assign_user
def create
@comment = @project.comments.new(params[:comment])
if @comment.save
redirect_to @project, :notice => 'Comment has been added'
else
redirect_to @project, :alert => 'Unable to add a comment'
end
end
def destroy
@comment = @project.comments.find(params[:id])
@comment.destroy
redirect_to @project, :notice => 'Comment has been deleted'
end
private
def load_project
@project = Project.find(params[:project_id])
end
def assign_user
params[:comment][:user_id] = current_user.id if params.has_key?(:comment)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment