Class: CommentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CommentsController
- 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
-
#create ⇒ Object
POST /comments POST /comments.json POST /comments.xml AJAX —————————————————————————-.
-
#destroy ⇒ Object
DELETE /comments/1 DELETE /comments/1.json DELETE /comments/1.xml not implemented —————————————————————————-.
-
#edit ⇒ Object
GET /comments/1/edit AJAX —————————————————————————-.
-
#index ⇒ Object
GET /comments GET /comments.json GET /comments.xml —————————————————————————-.
-
#new ⇒ Object
GET /comments/new GET /comments/new.json GET /comments/new.xml AJAX —————————————————————————-.
-
#update ⇒ Object
PUT /comments/1 PUT /comments/1.json PUT /comments/1.xml not implemened —————————————————————————-.
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
POST /comments POST /comments.json POST /comments.xml AJAX
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/comments_controller.rb', line 87 def create @comment = Comment.new(params[:comment]) # Make sure commentable object exists and is accessible to the current user. if @comment.commentable @comment.commentable_type.constantize.my.find(@comment.commentable.id) else raise ActiveRecord::RecordNotFound end @comment.save respond_with(@comment) rescue ActiveRecord::RecordNotFound # Kicks in if commentable asset was not found. (params[:comment][:commentable_type].downcase, :js, :xml) end |
#destroy ⇒ Object
DELETE /comments/1 DELETE /comments/1.json DELETE /comments/1.xml not implemented
121 122 123 124 125 126 127 128 |
# File 'app/controllers/comments_controller.rb', line 121 def destroy @comment = Comment.find(params[:id]) @comment.destroy respond_with(@comment) rescue ActiveRecord::RecordNotFound respond_to_not_found(:html, :js, :json, :xml) end |
#edit ⇒ Object
GET /comments/1/edit AJAX
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/comments_controller.rb', line 70 def edit @comment = Comment.find(params[:id]) if @comment.commentable @comment.commentable_type.constantize.my.find(@comment.commentable.id) else raise ActiveRecord::RecordNotFound end rescue ActiveRecord::RecordNotFound # Kicks in if commentable asset was not found. (params[:comment][:commentable_type].downcase, :js, :xml) end |
#index ⇒ Object
GET /comments GET /comments.json GET /comments.xml
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/comments_controller.rb', line 30 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 |
#new ⇒ Object
GET /comments/new GET /comments/new.json GET /comments/new.xml AJAX
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/comments_controller.rb', line 53 def new @comment = Comment.new @commentable = extract_commentable_name(params) if @commentable update_commentable_session @commentable.classify.constantize.my.find(params[:"#{@commentable}_id"]) end respond_with(@comment) rescue ActiveRecord::RecordNotFound # Kicks in if commentable asset was not found. (@commentable, :js) end |
#update ⇒ Object
PUT /comments/1 PUT /comments/1.json PUT /comments/1.xml not implemened
108 109 110 111 112 113 114 115 |
# File 'app/controllers/comments_controller.rb', line 108 def update @comment = Comment.find(params[:id]) @comment.update_attributes(params[:comment]) respond_with(@comment) rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :json, :xml) end |