我想在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已經搜索並嘗試了多個答案,其中沒有任何一個能夠工作,所以我已經將所有內容都回復到了原來的樣子。感謝您花時間解決這個問題,這意味着很多!
你在MRI上運行嗎,還是像JRuby這樣的其他平臺? – Unixmonkey
你使用的是Windows嗎? – Belder
我正在使用Windows 8.1。 – ds998