sam*_*101 5 debugging rubygems ruby-on-rails ruby-on-rails-4 byebug
当我尝试在带有 byebug 的 rails 中使用调试器时遇到问题......我安装了 byebug gem 没有任何问题......在 gemfile 中:
group :development, :test do
gem 'sqlite3'
gem 'byebug'
end
Run Code Online (Sandbox Code Playgroud)
将调试器放在我的控制器中:
class ArticlesController < ApplicationController
before_action :set_article, only: [:edit, :update, :show, :destroy]
def new
@article = Article.new
end
def create
debugger
@article = Article.new(article_params)
# @article.user = User.first
if @article.save
flash[:success] = "Article was successfully created"
redirect_to article_path(@article)
else
render 'new'
end
end
def show
end
def index
@articles = Article.all
end
def edit
end
def update
if @article.update(article_params)
flash[:success] = "Article was successfully updated"
redirect_to article_path(@article)
else
render 'edit'
end
end
def destroy
@article.destroy
flash[:danger] = "Article was successfully 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
Run Code Online (Sandbox Code Playgroud)
(我在 windwos 7 中使用 gitbash )问题是当我尝试调用 article_params 时,我只得到一个空行很长一段时间没有响应我试图重新启动我的服务器并再次尝试调试但同样的问题......这是一个问题的图片
这是来自 git bash 的代码(与图片中的相同):
5: @article = Article.new
6: end
7:
8: def create
9: debugger
=> 10: @article = Article.new(article_params)
11: # @article.user = User.first
12: if @article.save
13: flash[:success] = "Article was successfully created"
14: redirect_to article_path(@article)
(byebug) article_params
-(here goes the blank line)
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
对于我的一个应用程序来说效果很好。我正在使用它pry作为我的默认调试工具,并且只需插入byebug就可以完美地工作。
[58, 67] in /Users/../controllers/items_controller.rb
58:
59: # POST /items
60: # POST /items.json
61: def create
62: debugger
=> 63: @item = Item.new(item_params)
64:
65: respond_to do |format|
66: if @item.save
67: format.html { redirect_to edit_item_path(@item), notice: 'Item was successfully created.' }
(byebug) item_params
<ActionController::Parameters {"name"=>"asd", "description"=>"asdasd", "hub_id"=>1} permitted: true>
(byebug)
Run Code Online (Sandbox Code Playgroud)
所以,我认为我们需要更多代码。也许你的文章参数?
private
# Use callbacks to share common setup or constraints between actions.
def set_item
@item = Item.find(params[:id]).decorate
end
# Never trust parameters from the scary internet, only allow the white list through.
def item_params
params.require(:item).permit(
:photo,
:name,
:description,
:location_id,
:item_category_id,
:x_coordinates,
:y_coordinates,
:inspection_date
).merge(hub_id: current_hub)
end
Run Code Online (Sandbox Code Playgroud)