Create comments on splats

This commit is contained in:
Jason Zimdars
2024-08-19 14:14:26 -05:00
parent 117d5b1e2e
commit 6860a0ea36
4 changed files with 37 additions and 4 deletions
+17
View File
@@ -1,2 +1,19 @@
class CommentsController < ApplicationController
before_action :set_splat
def create
@comment = @splat.comments.create(comment_params)
@comment.save
redirect_to splat_path(@splat)
end
private
def comment_params
params.require(:comment).permit(:body)
end
def set_splat
@splat = Splat.find(params[:splat_id])
end
end
+18
View File
@@ -0,0 +1,18 @@
<div class="comment flex align-start gap">
<div class="flex align-center gap full-width">
<span class="avatar fill-black txt-reversed flex-item-no-shrink"><strong><%= Current.user.initials %></strong></span>
<header class="full-width flex align-center gap">
<strong><%= Current.user.name %></strong>
</header>
</div>
<div class="comment__body txt-align-start full-width">
<%= form_with model: [@splat, @splat.comments.build], class: "flex flex-column gap full-width" do | form | %>
<%= form.text_area :body, class: "input full-width", required: true, placeholder: "Type your comment…", rows: 4, autofocus: true %>
<%= form.button class: "btn btn--reversed center" do %>
<%= image_tag "check.svg", aria: { hidden: "true" }, size: 24%>
<span class="for-screen-reader">Save</span>
<% end %>
<% end %>
</div>
</div>
+1 -4
View File
@@ -40,8 +40,5 @@
<hr />
<%= render @splat.comments %>
<button class="btn btn--positive center">
<%= image_tag "add.svg", aria: { hidden: true }, size: 24 %>
<span class="for-screen-reader">Add a comment</span>
</button>
<%= render "comments/new" %>
</section>
+1
View File
@@ -5,6 +5,7 @@ Rails.application.routes.draw do
resources :splats do
resources :categories, shallow: true
resources :comments
end
resources :categories, only: :index