end
if params[:comment_id]
- comment = @review.comments.find(params[:comment_id].to_i)
- if comment
- comment.text=params[:text]
- comment.save!
- end
+ @review.edit_comment(params[:comment_id].to_i, params[:text])
else
- @review.comments.create!(:user => current_user, :text => params[:text])
+ @review.create_comment(:user => current_user, :text => params[:text])
end
-
+
render :partial => "reviews/view"
end
end
if @review
- comment=@review.comments.find(params[:comment_id].to_i)
- comment.delete if comment
+ @review.delete_comment(params[:comment_id].to_i)
end
render :partial => "reviews/view"
end
end
if params[:comment_id]
- comment=violation.review.comments.find(params[:comment_id].to_i)
- if comment
- comment.text=params[:text]
- comment.save!
- end
+ violation.review.edit_comment(params[:comment_id].to_i, params[:text])
else
- violation.review.comments.create!(:user => current_user, :text => params[:text])
+ violation.review.create_comment(:user => current_user, :text => params[:text])
end
render :partial => "resource/violation", :locals => { :violation => violation }
end
sanitize_violation(violation)
if violation.review
- comment=violation.review.comments.find(params[:comment_id].to_i)
- comment.delete if comment
+ violation.review.delete_comment(params[:comment_id].to_i)
end
render :partial => "resource/violation", :locals => { :violation => violation }
end
end
end
+ def create_comment(options={})
+ comments.create!(options)
+ touch
+ end
+
+ def edit_comment(comment_id, comment_text)
+ comment=comments.find(comment_id)
+ if comment
+ comment.text=comment_text
+ comment.save!
+ touch
+ end
+ end
+
+ def delete_comment(comment_id)
+ comment=comments.find(comment_id)
+ if comment
+ comment.delete
+ touch
+ end
+ end
+
def self.search(options={})
conditions=[]
values={}