diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 766995515..1b23c6839 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 diff --git a/app/views/comments/_new.html.erb b/app/views/comments/_new.html.erb new file mode 100644 index 000000000..9e4b19819 --- /dev/null +++ b/app/views/comments/_new.html.erb @@ -0,0 +1,18 @@ +
+
+ <%= Current.user.initials %> +
+ <%= Current.user.name %> +
+
+
+ <%= 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%> + Save + <% end %> + <% end %> +
+
diff --git a/app/views/splats/show.html.erb b/app/views/splats/show.html.erb index 1566a1951..3ccb94beb 100644 --- a/app/views/splats/show.html.erb +++ b/app/views/splats/show.html.erb @@ -40,8 +40,5 @@
<%= render @splat.comments %> - + <%= render "comments/new" %> diff --git a/config/routes.rb b/config/routes.rb index c1ef5b0e3..12b7555b3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ Rails.application.routes.draw do resources :splats do resources :categories, shallow: true + resources :comments end resources :categories, only: :index