Class: ForemanDatacenter::CommentsController
- Inherits:
-
ApplicationController
show all
- Includes:
- ForemanDatacenter::Controller::Parameters::Comment
- Defined in:
- app/controllers/foreman_datacenter/comments_controller.rb
Instance Method Summary
collapse
#action_permission, #controller_permission, #find_resource, #not_found, #resource_class, #resource_class_for, #resource_finder, #resource_name, #resource_scope, #scope_for
Instance Method Details
#create ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'app/controllers/foreman_datacenter/comments_controller.rb', line 22
def create
@comment = @commentable..new(.merge(user_id: current_user.id))
if @comment.save
process_success success_redirect: (@comment),
success_msg: "Comment successfully created."
else
process_error redirect: "/datacenter/#{@resource}/#{@id}", :error_msg => _("Failed: %s") % (e)
end
end
|
#destroy ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/controllers/foreman_datacenter/comments_controller.rb', line 46
def destroy
@comment = ForemanDatacenter::Comment.find(params[:id])
if @comment.user == current_user or @comment.user.nil? or current_user.admin?
if @comment.destroy
process_success :success_redirect => (@comment, true), success_msg: "Comment successfully deleted."
else
process_error :redirect => (@comment, true), :error_msg => _("Failed: %s") % (e)
end
else
process_error :redirect => (@comment, true), :error_msg => _("You can delete only your own comments")
end
end
|
#edit ⇒ Object
15
16
17
18
19
20
|
# File 'app/controllers/foreman_datacenter/comments_controller.rb', line 15
def edit
@comment = ForemanDatacenter::Comment.find(params[:id])
@parent = @comment.parent
@resource_class = @comment..split("::")[1]
@current_user = current_user
end
|
#new ⇒ Object
7
8
9
10
11
12
13
|
# File 'app/controllers/foreman_datacenter/comments_controller.rb', line 7
def new
@comment = ForemanDatacenter::Comment.new
@parent = ForemanDatacenter::Comment.find(params[:parent_id])
@resource_class = @parent..gsub("ForemanDatacenter::","")
@resource = @resource_class.pluralize.split(/(?<!\s)(?=[A-Z])/).join('_').downcase
@commentable = load_resource(@resource, @parent.)
end
|
#update ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/controllers/foreman_datacenter/comments_controller.rb', line 32
def update
@comment = ForemanDatacenter::Comment.find(params[:id])
@resource = @comment..split("::")[1]
if @comment.user == current_user or @comment.user.nil? or current_user.admin?
if @comment.update(.merge(user_id: current_user.id))
process_success :success_redirect => (@comment), success_msg: "Comment successfully updated."
else
process_error :redirect => (@comment), :error_msg => _("Failed: %s") % (e)
end
else
process_error :redirect => (@comment), :error_msg => _("You can edit only your own comments")
end
end
|