Class: CommentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CommentsController
- Defined in:
- app/controllers/comments_controller.rb
Overview
Copyright © 2008-2013 Michael Dvorkin and contributors.
Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php
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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/comments_controller.rb', line 67 def create attributes = params[:comment] || {} attributes.merge!(:user_id => current_user.id) @comment = Comment.new(attributes) # 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) (model.downcase) end @comment.save respond_with(@comment) end |
#destroy ⇒ Object
DELETE /comments/1 DELETE /comments/1.json DELETE /comments/1.xml not implemented
96 97 98 99 100 |
# File 'app/controllers/comments_controller.rb', line 96 def destroy @comment = Comment.find(params[:id]) @comment.destroy respond_with(@comment) end |
#edit ⇒ Object
GET /comments/1/edit AJAX
54 55 56 57 58 59 60 61 |
# File 'app/controllers/comments_controller.rb', line 54 def edit @comment = Comment.find(params[:id]) model, id = @comment.commentable_type, @comment.commentable_id unless model.constantize.my.find_by_id(id) (model.downcase) end end |
#index ⇒ Object
GET /comments GET /comments.json GET /comments.xml
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/comments_controller.rb', line 15 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
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/comments_controller.rb', line 38 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"]) (@commentable) and return end end respond_with(@comment) end |
#update ⇒ Object
PUT /comments/1 PUT /comments/1.json PUT /comments/1.xml not implemened
86 87 88 89 90 |
# File 'app/controllers/comments_controller.rb', line 86 def update @comment = Comment.find(params[:id]) @comment.update_attributes(params[:comment]) respond_with(@comment) end |