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 —————————————————————————-.
-
#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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/comments_controller.rb', line 45 def create @comment = Comment.new( comment_params.merge(user_id: current_user.id) ) # Make sure commentable object exists and is accessible to the current user. model = find_class(@comment.commentable_type) id = @comment.commentable_id if model.my(current_user).find_by_id(id) @comment.save respond_with(@comment) else (model.name.downcase) end end |
#destroy ⇒ Object
DELETE /comments/1 DELETE /comments/1.json DELETE /comments/1.xml not implemented
74 75 76 77 78 |
# File 'app/controllers/comments_controller.rb', line 74 def destroy @comment = Comment.find(params[:id]) @comment.destroy respond_with(@comment) end |
#edit ⇒ Object
GET /comments/1/edit AJAX
33 34 35 36 37 38 39 |
# File 'app/controllers/comments_controller.rb', line 33 def edit @comment = Comment.find(params[:id]) model = find_class(@comment.commentable_type) id = @comment.commentable_id (model.downcase) unless model.my(current_user).find_by_id(id) end |
#index ⇒ Object
GET /comments GET /comments.json GET /comments.xml
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/comments_controller.rb', line 13 def index @commentable = extract_commentable_name(params) if @commentable @asset = find_class(@commentable).my(current_user).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 plain: flash[:warning], status: :not_found } format.xml { render plain: flash[:warning], status: :not_found } end end |
#update ⇒ Object
PUT /comments/1 PUT /comments/1.json PUT /comments/1.xml not implemened
64 65 66 67 68 |
# File 'app/controllers/comments_controller.rb', line 64 def update @comment = Comment.find(params[:id]) @comment.update(comment_params) respond_with(@comment) end |