5

byebugを使用してレールでデバッガーを使用しようとすると問題が発生します...問題なくbyebug gemをインストールしました... gemfileに:

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)

誰でも助けてくれますか?

4

2 に答える 2

4

それで、Stackoverflow Byebug でこの質問を見つけましたが、Windows を完全にサポートしていますか? 2017年1月に投稿されたものです。

Github の問題を追跡したところ、Rails でコミットが見つかりました (申し訳ありませんが、私のネットワークは github をブロックしているので、好きではありません)。mri プラットフォームは Windows ではサポートされておらず、RailsGemfileジェネレーター テンプレートが更新されました。

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

変更を加えてコードを実行したbyebugところ、Windows で動作するようになりました。

変更後にバンドルを実行する必要がある場合があります。

于 2017-05-14T23:37:12.337 に答える
1

私のアプリの1つで問題なく動作します。私は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
于 2016-06-15T12:40:18.367 に答える