繁体   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