2017-08-06 92 views
1

我想在Rails中调试一个项目。但是,我经常在浏览器中得到这个错误:undefined local variable或method byebug'for#“<”ArticlesController:0x9430c68>。 的文章控制器的代码是:Rails调试错误

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 

我:

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 

逻辑上byebug命令,在“创建” action.The宝石“byebug”安装在Gemfile中出现错误在Rails 5中工作,而我的IDE是Atom.I已经搜索并尝试了多个答案,其中没有任何一个能够工作,所以我已经将所有内容都回复到了原来的样子。感谢您花时间解决这个问题,这意味着很多!

+0

你在MRI上运行吗,还是像JRuby这样的其他平台? – Unixmonkey

+0

你使用的是Windows吗? – Belder

+0

我正在使用Windows 8.1。 – ds998

回答

0

如果您使用的是Windows,请尝试更改

gem 'byebug', platform: :mri 

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

否则,因为人们似乎有很多使用byebug与Windows的问题,我会尝试使用不同的调试器像pry

使用Rails将想要的pry-rails gem添加到您的Gemfile中,然后运行bundle install

+0

我试过了,仍然没有工作 - 计算机在require行中无法识别byebug(“无法加载这样的文件--byebug”)。 – ds998

+0

嗯...我知道很多人在Windows上使用byebug都存在问题。我编辑了我的答案,并建议查看pry调试器宝石。 – Belder

+0

已安装pry.Still得到类似的错误,除了这次是pry(“无法加载这样的文件--pry”)在线“require'pry'”。我厌倦了将它移动到Controller类之上,但是同样的错误显示up.Pry毫无疑问安装,我通过Git Bash检查。你有任何其他的调试宝石建议? – ds998