5

当我尝试在带有 byebug 的 rails 中使用调试器时遇到问题...我安装了 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,所以我不喜欢他们)。windows 不支持 mri 平台,railsGemfile生成器模板现已更新为。

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

我进行了更改,然后运行了我的代码,byebug现在可以在 Windows 上运行!

更改后可能需要运行 bundle。

于 2017-05-14T23:37:12.337 回答
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 回答