Commit 3971f117 authored by Klaus Stein's avatar Klaus Stein
Browse files

I can edit and delete comments now (It's a mess)

parent c0179cf4
......@@ -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
......
......@@ -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;
}
......
<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 %>
<%= turbo_frame_tag :new_comment do %>
<%= link_to 'New comment', new_polymorphic_path([parent, :comment]), method: :get %>
<% end %>
<%= 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 }) %>
<%= turbo_stream.remove(@comment) %>
<%= turbo_stream.update(@comment, partial: "comments/form", locals: { comment: @comment, parent: @comment.commentable }) %>
<h1>New Comment</h1>
<%= render 'form', comment: @comment %>
<%#= render 'form', comment: @comment %>
<%= link_to 'Back', comments_path %>
<%= turbo_stream.update(:new_comment, partial: "comments/form", locals: { comment: @comment, parent: @parent }) %>
<%= turbo_stream.update(@comment, partial: "comments/comment", locals: { comment: @comment, parent: @comment.commentable }) %>
......@@ -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>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment