繁体   English   中英

导轨中的调试器与byebug无法正常工作

[英]debugger in rails with byebug not working

当我尝试在带有byebug的rails中使用调试器时出现问题...我在gemfile中安装了byebug gem而没有任何问题:

group :development, :test do
  gem 'sqlite3'
  gem 'byebug'
end

把调试器放在我的控制器中:

class ArticlesController < ApplicationController
  before_action :set_article, only: [:edit, :update, :show, :destroy]

  def new
      @article = Article.new
  end

  def create
      debugger
      @article = Article.new(article_params)
      # @article.user = User.first
    if @article.save
      flash[:success] = "Article was successfully created"
      redirect_to article_path(@article)
    else
      render 'new'
    end
  end

  def show
  end

  def index
    @articles = Article.all
  end

  def edit
  end

  def update
    if @article.update(article_params)
      flash[:success] = "Article was successfully updated"
      redirect_to article_path(@article)
    else
        render 'edit'
    end
  end

  def destroy
    @article.destroy
    flash[:danger] = "Article was successfully deleted"
    redirect_to articles_path

  end

  private
    def set_article
        @article = Article.find(params[:id])
    end
    def article_params
        params.require(:article).permit(:title, :description)
    end

end

(我在windwos 7中使用gitbash)问题是,当我尝试调用article_params时,我得到一个空白行只有很长时间没有响应我试图重新启动我的服务器并尝试再次调试但同样的问题.... 这是一个图像的问题

这是来自git bash的代码(在图像中是相同的):

    5:          @article = Article.new
    6:  end
    7:
    8:   def create
    9:                  debugger
=> 10:          @article = Article.new(article_params)
   11:          # @article.user = User.first
   12:     if @article.save
   13:       flash[:success] = "Article was successfully created"
   14:       redirect_to article_path(@article)
(byebug) article_params
-(here goes the blank line)

任何人都可以帮忙吗?

所以我发现Stackoverflow上的这个问题Byebug是否完全支持Windows? 发布于2017年1月。

我跟着Github上的问题找到了一个在rails中的提交(抱歉我的网络阻止了github所以不喜欢它们)。 Windows和rails不支持mri平台Gemfile生成器模板现已更新为。

gem 'byebug', platform: [:mri, :mingw, :x64_mingw]

我做了更改然后运行我的代码和byebug现在在Windows上工作!

更改后可能需要运行bundle。

适用于我的某个应用程序。 我使用pry作为我的默认调试工具,只是删除byebug中准确无误地运行。

  [58, 67] in /Users/../controllers/items_controller.rb
     58:
     59:   # POST /items
     60:   # POST /items.json
     61:   def create
     62:     debugger
  => 63:     @item = Item.new(item_params)
     64:
     65:     respond_to do |format|
     66:       if @item.save
     67:         format.html { redirect_to edit_item_path(@item), notice: 'Item was successfully created.' }
  (byebug) item_params
  <ActionController::Parameters {"name"=>"asd", "description"=>"asdasd", "hub_id"=>1} permitted: true>
  (byebug)

所以,我认为我们需要更多的代码。 也许你的文章参考?

private
  # Use callbacks to share common setup or constraints between actions.
  def set_item
    @item = Item.find(params[:id]).decorate
  end

  # Never trust parameters from the scary internet, only allow the white list through.
  def item_params
    params.require(:item).permit(
      :photo,
      :name,
      :description,
      :location_id,
      :item_category_id,
      :x_coordinates,
      :y_coordinates,
      :inspection_date
    ).merge(hub_id: current_hub)
  end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM