Class: ForemanDatacenter::CommentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ForemanDatacenter::CommentsController
- Defined in:
- app/controllers/foreman_datacenter/comments_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'app/controllers/foreman_datacenter/comments_controller.rb', line 16 def create @comment = @commentable.comments.new(comment_params.merge(user_id: User.current.id)) if @comment.save process_success :success_redirect => "/datacenter/#{@resource}/#{@id}#comment-#{@comment.id}" else process_error :redirect => "/datacenter/#{@resource}/#{@id}", :error_msg => _("Failed: %s") % (e) end end |
#destroy ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/foreman_datacenter/comments_controller.rb', line 40 def destroy @comment = Comment.find(params[:id]) if @comment.user == @current_user or @comment.user.nil? if @comment.destroy process_success :success_redirect => "/datacenter/#{@resource}/#{@id}#comment-#{@comment.id}" else process_error :redirect => "/datacenter/#{@resource}/#{@id}", :error_msg => _("Failed: %s") % (e) end else process_error :redirect => "/datacenter/#{@resource}/#{@id}", :error_msg => _("You can delete only your own comments") end end |
#edit ⇒ Object
11 12 13 14 |
# File 'app/controllers/foreman_datacenter/comments_controller.rb', line 11 def edit @comment = Comment.find(params[:id]) @parent = @comment.parent end |
#new ⇒ Object
6 7 8 9 |
# File 'app/controllers/foreman_datacenter/comments_controller.rb', line 6 def new @comment = Comment.new @parent = Comment.find(params[:parent_id]) end |
#update ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/foreman_datacenter/comments_controller.rb', line 25 def update @comment = Comment.find(params[:id]) @device = find_commentable(@comment) @submodule = parse_submodule(@comment) if @comment.user == @current_user or @comment.user.nil? if @comment.update(comment_params) process_success :success_redirect => "/datacenter/#{@submodule}/#{@comment.commentable_id}#comment-#{@comment.id}" else process_error :redirect => "/datacenter/#{@submodule}/#{@comment.commentable_id}#comment-#{@comment.id}", :error_msg => _("Failed: %s") % (e) end else process_error :redirect => "/datacenter/#{@submodule}/#{@comment.commentable_id}#comment-#{@comment.id}", :error_msg => _("You can edit only your own comments") end end |