Create comments on splats
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -5,6 +5,7 @@ Rails.application.routes.draw do
|
||||
|
||||
resources :splats do
|
||||
resources :categories, shallow: true
|
||||
resources :comments
|
||||
end
|
||||
|
||||
resources :categories, only: :index
|
||||
|
||||
Reference in New Issue
Block a user