ruby-on-rails 在浏览器中看不到Ruby on Rails调试控制台

xeufq47z  于 2023-02-26  发布在  Ruby
关注(0)|答案(1)|浏览(136)

当我在我的控制器中做一个raise时,创建如下:

class RequestsController < ApplicationController
  before_action :request_params, only: [:create]

  def create
    raise
    @request = Request.new(request_params)
    if @request.save
      RequestMailer.received_request(@request).deliver_now
      flash.now[:success] = {message: t(".success"), body: ""}
      @request = Request.new
      respond_to do |format|
        format.turbo_stream
      end
    else
      flash.now[:error] = {message: t(".error"), body: @request.errors.full_messages.join(", ")}
      render turbo_stream: turbo_stream.replace(:flash_messages, partial: "shared/flash_messages")
    end
  end

  private

  def request_params
    params.require(:request).permit(:first_name, :last_name, :email, :subject, :message, :date)
  end
end

我无法看到浏览器中带有该断点的浏览器控制台。我只能在本地控制台中看到错误,无法正确调试:

web    | Started POST "/requests" for ::1 at 2023-02-20 12:52:10 -0600
web    | Processing by RequestsController#create as TURBO_STREAM
web    |   Parameters: {"authenticity_token"=>"[FILTERED]", "request"=>{"first_name"=>"", "last_name"=>"", "subject"=>"", "email"=>"", "message"=>"", "date"=>""}, "commit"=>"Submit"}
web    | Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms | Allocations: 954)
web    | 
web    | 
web    |   
web    | RuntimeError ():
web    |   
web    | app/controllers/requests_controller.rb:5:in `create'

我还在development.rb中将all_requests_local = true设置为true

fnvucqvd

fnvucqvd1#

使用binding.pry停止控制台中的程序。我现在调试得很好。
如果binding.pry提示未出现,请执行以下操作:使用tmux在不同的终端运行下一个进程:

  • 观察:css
  • 监视:Web

或者简单地打开两个终端,一个运行rails s,另一个运行bin/rails tailwindcss:watch(或者你正在使用的任何编译器,比如webpack)
似乎有css和web是隐藏binding.pry prompt

相关问题