簡體   English   中英

Rails調試錯誤

[英]Rails debugging error

我正在嘗試在Rails中調試項目。但是,我在瀏覽器中不斷遇到此錯誤:#“ <” ArticlesController:0x9430c68>的未定義局部變量或方法'byebug'。 Articles控制器的代碼為:

class ArticlesController < ApplicationController
  before_action :set_article,only: [:edit,:update,:show,:destroy]
  def index
    @articles = Article.all
  end

  def new
    @article = Article.new
  end

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

  def edit

  end

  def update

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

  def show

  end

  def destroy

    @article.destroy
    flash[:danger]="Article was succesfully 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

該錯誤在'create'操作中按邏輯顯示在byebug命令上。gem'byebug'安裝在Gemfile中:

 group :development, :test do
   gem 'sqlite3'
   # Call 'byebug' anywhere in the code to stop execution and get a debugger 
   console
   gem 'byebug', platform: :mri

 end

我在Rails 5中工作,我的IDE是Atom。我已經搜索並嘗試了多個答案,但都沒有成功,因此我將一切恢復了原樣。感謝您抽出時間來解決此問題,這意味着很多!

如果您使用的是Windows,請嘗試更改

gem 'byebug', platform: :mri

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

否則,因為人們似乎有很多使用byebug與Windows的問題,我會嘗試使用不同的調試器像pry

使用Rails,您想將pry pry-rails gem添加到Gemfile中,然后運行bundle install

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM