1

Here is my github to my project. I put byebug into all of my controller actions to debug this login form...

<h1>Login</h1>
<%= form_with model: @user do |form| %>
  <%= render "partials/usererrorform" %>
  <%= form.label :user_name %>
  <%= form.text_field :user_name %>
  <br>  
  <%= form.label :password %>
  <%= form.password_field :password %>
  <br>
  <%= form.submit "LogOn"%>
  <% end %>
class LogInController < ApplicationController
  include ApplicationHelper
  ...
    def post_login
    byebug
    @user = User.find_by(user_name: params[:user][:user_name])
    if @user && @user.authenticate(params[:user_name][:password])
      session[:user_name_id] = @user.id
      redirect_to user_path(@user) 
      
    else
      @user ||= User.new
      render :login
    end
   end
  ...
  end

Could someone tell me why my byebug isn't showing up in my terminal when I click LogOn?

This is the output when I click LogOn...

Started POST "/users" for ::1 at 2020-11-10 09:34:53 -0600
   (0.3ms)  SELECT sqlite_version(*)
   (0.1ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by UsersController#create as JS
  Parameters: {"authenticity_token"=>"tg1lTsGuYekpNftf6PxqaBLY1LJ61uS/xM/6YwOT2JS3siDaFe7RJCw57JdvNJrDJbRJoB9pHl8B9BE1oBPTug==", "user"=>{"user_name"=>"admin", "password"=>"[FILTERED]"}, "commit"=>"LogOn"}
  Rendering users/new.html.erb within layouts/application
  Rendered partials/_usererrorform.html.erb (Duration: 0.5ms | Allocations: 317)
  Rendered partials/_userform.html.erb (Duration: 6.5ms | Allocations: 4161)
  Rendered users/new.html.erb within layouts/application (Duration: 7.2ms | Allocations: 4634)
[Webpacker] Everything's up-to-date. Nothing to do
Completed 200 OK in 246ms (Views: 47.0ms | ActiveRecord: 0.8ms | Allocations: 29844)

Where am I going wrong? Why isn't the byebug working?

Kim
  • 23
  • 7

1 Answers1

1

In your log output, the controller being hit is UsersController#create, not LogInController#post_login. You'll either need to change up the form to hit this controller, or stick your byebug into the UsersController#create action instead.

Processing by UsersController#create as JS
Msencenb
  • 5,675
  • 11
  • 52
  • 84