Class: DmCore::Admin::CommentsController
- Inherits:
-
AdminController
- Object
- AdminController
- DmCore::Admin::CommentsController
- Includes:
- PermittedParams
- Defined in:
- app/controllers/dm_core/admin/comments_controller.rb
Overview
Common controller for handling comments in the admin interface pathfindersoftware.com/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/
Instance Method Summary collapse
-
#create ⇒ Object
Create a comment :commenter_type => object name of commenting object :commenter_id => object id of commenting object :name => optional prefix of association to use (eg. ‘private’ for private_comments) :comment => text of comment ——————————————————————————.
-
#destroy ⇒ Object
——————————————————————————.
-
#edit ⇒ Object
——————————————————————————.
-
#update ⇒ Object
——————————————————————————.
Methods included from PermittedParams
#account_params, #comment_params, #devise_sign_up_params, #user_params, #user_profile_direct_params, #user_profile_params
Instance Method Details
#create ⇒ Object
Create a comment :commenter_type => object name of commenting object :commenter_id => object id of commenting object :name => optional prefix of association to use (eg. ‘private’ for private_comments) :comment => text of comment
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/dm_core/admin/comments_controller.rb', line 15 def create params[:name] ||= 'comments' raise "Invalid Parameter" unless params[:name].end_with?('comments') association = params[:name].to_sym respond_to do |format| if @commenter.respond_to? association @comment = @commenter.send(association).create(comment_params.merge(user_id: current_user.id)) format.html { redirect_to :back } format.js else format.html { redirect_to :back } end end end |
#destroy ⇒ Object
50 51 52 53 54 55 56 |
# File 'app/controllers/dm_core/admin/comments_controller.rb', line 50 def destroy @comment.destroy if can?(:manage, :all) #|| comment.user == current_user respond_to do |format| format.html { redirect_to :back } format.js end end |
#edit ⇒ Object
32 33 34 35 36 37 |
# File 'app/controllers/dm_core/admin/comments_controller.rb', line 32 def edit respond_to do |format| format.html { redirect_to :back } format.js end end |
#update ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/dm_core/admin/comments_controller.rb', line 40 def update respond_to do |format| if @comment.update_attributes(comment_params) format.html { redirect_to :back } format.js end end end |