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>. The code for the Articles Controller is:
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:
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!
If you are using Windows, try changing
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
.
With Rails you want to add the pry-rails gem
into your Gemfile then run bundle install
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.