Class: CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/comments_controller.rb

Overview

Fat Free CRM Copyright © 2008-2011 by Michael Dvorkin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.


Constant Summary collapse

COMMENTABLE =
%w(account_id campaign_id contact_id lead_id opportunity_id task_id).freeze

Instance Method Summary collapse

Methods inherited from ApplicationController

#auto_complete

Instance Method Details

#createObject

POST /comments POST /comments.json POST /comments.xml AJAX




79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/comments_controller.rb', line 79

def create
  @comment = Comment.new(params[:comment])

  # Make sure commentable object exists and is accessible to the current user.
  model, id = @comment.commentable_type, @comment.commentable_id
  unless model.constantize.my.find_by_id(id)
    respond_to_related_not_found(model.downcase)
  end

  @comment.save
  respond_with(@comment)
end

#destroyObject

DELETE /comments/1 DELETE /comments/1.json DELETE /comments/1.xml not implemented




106
107
108
109
110
# File 'app/controllers/comments_controller.rb', line 106

def destroy
  @comment = Comment.find(params[:id])
  @comment.destroy
  respond_with(@comment)
end

#editObject

GET /comments/1/edit AJAX




66
67
68
69
70
71
72
73
# File 'app/controllers/comments_controller.rb', line 66

def edit
  @comment = Comment.find(params[:id])

  model, id = @comment.commentable_type, @comment.commentable_id
  unless model.constantize.my.find_by_id(id)
    respond_to_related_not_found(model.downcase)
  end
end

#indexObject

GET /comments GET /comments.json GET /comments.xml




27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/comments_controller.rb', line 27

def index
  @commentable = extract_commentable_name(params)
  if @commentable
    @asset = @commentable.classify.constantize.my.find(params[:"#{@commentable}_id"])
    @comments = @asset.comments.order("created_at DESC")
  end
  respond_with(@comments) do |format|
    format.html { redirect_to @asset }
  end

rescue ActiveRecord::RecordNotFound # Kicks in if @asset was not found.
  flash[:warning] = t(:msg_assets_not_available, "notes")
  respond_to do |format|
    format.html { redirect_to root_url }
    format.json { render :text => flash[:warning], :status => :not_found }
    format.xml  { render :text => flash[:warning], :status => :not_found }
  end
end

#newObject

GET /comments/new GET /comments/new.json GET /comments/new.xml AJAX




50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/comments_controller.rb', line 50

def new
  @comment = Comment.new
  @commentable = extract_commentable_name(params)

  if @commentable
    update_commentable_session
    unless @commentable.classify.constantize.my.find_by_id(params[:"#{@commentable}_id"])
      respond_to_related_not_found(@commentable) and return
    end
  end

  respond_with(@comment)
end

#updateObject

PUT /comments/1 PUT /comments/1.json PUT /comments/1.xml not implemened




96
97
98
99
100
# File 'app/controllers/comments_controller.rb', line 96

def update
  @comment = Comment.find(params[:id])
  @comment.update_attributes(params[:comment])
  respond_with(@comment)
end