Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
urbanmetamapping
platform
MapMyMaps-p1
Commits
3971f117
Commit
3971f117
authored
Mar 07, 2022
by
Klaus Stein
Browse files
I can edit and delete comments now (It's a mess)
parent
c0179cf4
Changes
11
Hide whitespace changes
Inline
Side-by-side
app/controllers/comments_controller.rb
View file @
3971f117
...
...
@@ -17,7 +17,7 @@ class CommentsController < ApplicationController
@parent
=
map
end
@comment
=
Comment
.
new
@comments
=
@parent
&
.
comments
||
Comment
.
all
@comments
=
@parent
&
.
comments
||
Comment
.
all
end
# GET /comments/1/edit
...
...
@@ -51,6 +51,9 @@ class CommentsController < ApplicationController
# PATCH/PUT /comments/1 or /comments/1.json
def
update
@comment
.
update
(
comment_params
)
end
def
update_
respond_to
do
|
format
|
if
@comment
.
update
(
comment_params
)
format
.
html
{
redirect_to
@comment
,
notice:
"Comment was successfully updated."
}
...
...
@@ -65,10 +68,10 @@ class CommentsController < ApplicationController
# DELETE /comments/1 or /comments/1.json
def
destroy
@comment
.
destroy
respond_to
do
|
format
|
format
.
html
{
redirect_to
comments_url
,
notice:
"Comment was successfully destroyed."
}
format
.
json
{
head
:no_content
}
end
#
respond_to do |format|
#
format.html { redirect_to comments_url, notice: "Comment was successfully destroyed." }
#
format.json { head :no_content }
#
end
end
private
...
...
app/frontend/stylesheets/_map.scss
View file @
3971f117
...
...
@@ -119,6 +119,11 @@ main.show.map {
margin-bottom
:
1rem
;
}
.comment
{
border-left
:
5px
solid
#dcc
;
padding-left
:
2px
;
header
{
padding
:
0
0
.5rem
;
}
p
{
font-style
:
italic
;
}
...
...
app/views/comments/_comment.html.erb
View file @
3971f117
<section
id=
"
<%=
dom_id
(
comment
)
%>
"
class=
"comment"
data-stream-enter-class=
"animate-item-in"
data-stream-exit-class=
"animate-item-out"
>
<header>
<span
class=
"user"
>
<%=
comment
.
user
.
username
%>
</span>
<span
class=
"date"
>
<%=
comment
.
updated_at
%>
</span>
</header>
<p>
<%=
comment
.
text
%>
</p>
</section>
<%=
turbo_frame_tag
comment
do
%>
<section
id=
"
<%=
dom_id
(
comment
)
%>
"
class=
"comment"
data-stream-enter-class=
"animate-item-in"
data-stream-exit-class=
"animate-item-out"
>
<header>
<span
class=
"user"
>
<%=
comment
.
user
.
username
%>
</span>
<span
class=
"date"
>
<%=
comment
.
updated_at
%>
</span>
<span
class=
"actions"
>
<%
if
comment
.
user
==
current_user
%>
<%=
actionlink
(
edit_polymorphic_path
([
comment
.
commentable
,
comment
]),
lid:
comment
.
id
,
svgid:
'#icon-edit'
,
title:
'Edit'
)
%>
<%#= link_to "Edit", edit_polymorphic_path([comment.commentable, comment]) %>
<%=
destroylink
(
polymorphic_path
([
comment
.
commentable
,
comment
]),
lid:
comment
.
id
)
%>
<%
end
%>
</span>
</header>
<p>
<%=
comment
.
text
%>
</p>
</section>
<%
end
%>
app/views/comments/_new.html.erb
0 → 100644
View file @
3971f117
<%=
turbo_frame_tag
:new_comment
do
%>
<%=
link_to
'New comment'
,
new_polymorphic_path
([
parent
,
:comment
]),
method: :get
%>
<%
end
%>
app/views/comments/create.turbo_stream.erb
View file @
3971f117
<%=
turbo_stream
.
prepend
(
"comments-list"
,
partial:
"comments/comment"
,
locals:
{
comment:
@comment
})
%>
<%=
turbo_stream
.
update
(
"comments-count"
,
partial:
"comments/count"
,
locals:
{
comments:
@comments
})
%>
<%=
turbo_stream
.
update
(
"new_comment"
,
partial:
"comments/
form
"
,
locals:
{
comment:
Comment
.
new
,
parent:
@parent
})
%>
<%=
turbo_stream
.
update
(
"new_comment"
,
partial:
"comments/
new
"
,
locals:
{
comment:
Comment
.
new
,
parent:
@parent
})
%>
app/views/comments/destroy.turbo_stream.erb
0 → 100644
View file @
3971f117
<%=
turbo_stream
.
remove
(
@comment
)
%>
app/views/comments/edit.turbo_stream.erb
0 → 100644
View file @
3971f117
<%=
turbo_stream
.
update
(
@comment
,
partial:
"comments/form"
,
locals:
{
comment:
@comment
,
parent:
@comment
.
commentable
})
%>
app/views/comments/new.html.erb
View file @
3971f117
<h1>
New Comment
</h1>
<%=
render
'form'
,
comment:
@comment
%>
<%
#
= render 'form', comment: @comment %>
<%=
link_to
'Back'
,
comments_path
%>
app/views/comments/new.turbo_stream.erb
0 → 100644
View file @
3971f117
<%=
turbo_stream
.
update
(
:new_comment
,
partial:
"comments/form"
,
locals:
{
comment:
@comment
,
parent:
@parent
})
%>
app/views/comments/update.turbo_stream.erb
0 → 100644
View file @
3971f117
<%=
turbo_stream
.
update
(
@comment
,
partial:
"comments/comment"
,
locals:
{
comment:
@comment
,
parent:
@comment
.
commentable
})
%>
app/views/maps/show.html.erb
View file @
3971f117
...
...
@@ -49,9 +49,10 @@
<details
open=
"open"
class=
"comments"
>
<summary
id=
"comments-count"
>
<%=
render
'comments/count'
,
comments:
@map
.
comments
%>
</summary>
<div
class=
"body"
>
<%
if
current_user
%>
<%=
render
'comments/form'
,
comment:
Comment
.
new
,
parent:
@map
%>
<%
end
%>
<%
if
current_user
%>
<%=
render
'comments/new'
,
parent:
@map
%>
<%#= render 'comments/form', comment: Comment.new, parent: @map %>
<%
end
%>
<hr
/>
<%=
render
'comments/list'
,
comments:
@map
.
comments
.
order
(
updated_at: :desc
)
%>
</div>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment