diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d8a8b1e..3ef92a5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,13 +5,13 @@ class ApplicationController < ActionController::Base # Make sure you run `rails sample_data` # Delete this code when the issue is resolved. - # helper_method :current_user + helper_method :current_user - # def current_user - # @alice ||= User.find_by! username: "alice" - # end + def current_user + @alice ||= User.find_by! username: "alice" + end - # skip_forgery_protection + skip_forgery_protection # End hacks. ############################################################################## diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 5b62df9..98f709b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -33,9 +33,11 @@ def create if @comment.save format.html { redirect_back fallback_location: root_path, notice: "Comment was successfully created." } format.json { render :show, status: :created, location: @comment } + format.js else format.html { render :new, status: :unprocessable_entity } format.json { render json: @comment.errors, status: :unprocessable_entity } + end end end diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index f289224..3a93812 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,5 +1,5 @@ -
  • - <%= form_with(model: comment) do |form| %> +
  • + <%= form_with(model: comment, local:false) do |form| %> <% if comment.errors.any? %>