2017-08-06 90 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