[英]Rails debugging error
I'm trying to debug a project in Rails.However,I constantly get this error in the browser:undefined local variable or method `byebug' for #"<"ArticlesController:0x9430c68>. 我正在尝试在Rails中调试项目。但是,我在浏览器中不断遇到此错误:#“ <” ArticlesController:0x9430c68>的未定义局部变量或方法'byebug'。 The code for the Articles Controller is: 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
The error appears logically on the byebug command in the 'create' action.The gem 'byebug' is installed in the Gemfile: 该错误在'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
I work in Rails 5,and my IDE is Atom.I have searched and tried multiple answers,none of which have worked,so I have returned everything to how it was.Thank you for taking time to solve this problem,it means a lot! 我在Rails 5中工作,我的IDE是Atom。我已经搜索并尝试了多个答案,但都没有成功,因此我将一切恢复了原样。感谢您抽出时间来解决此问题,这意味着很多!
If you are using Windows, try changing 如果您使用的是Windows,请尝试更改
gem 'byebug', platform: :mri
to 至
gem 'byebug', platform: [:mri, :mingw, :x64_mingw]
Otherwise, since people seem to have a lot of problems using byebug with Windows, I would try using a different debugger like pry
. 否则,因为人们似乎有很多使用byebug与Windows的问题,我会尝试使用不同的调试器像pry
。
With Rails you want to add the pry-rails gem
into your Gemfile then run bundle install
. 使用Rails,您想将pry pry-rails gem
添加到Gemfile中,然后运行bundle install
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.