Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debugger in rails with byebug not working

I have a problem when I try using debugger in rails with byebug...I installed the byebug gem without any problems ... in gemfile :

group :development, :test do
  gem 'sqlite3'
  gem 'byebug'
end

put the debugger in my controller:

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

(I am using gitbash in windwos 7 ) The problem is when I try calling article_params I get a blank line only for long time with no respond I tried to restart my server and and tried debugging again but same problem....Here is an image for the problem

here is the code from git bash (is the same in the image):

    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)

Any one can help please?

like image 548
sam0101 Avatar asked Jun 15 '16 12:06

sam0101


People also ask

How do you debug Byebug?

wherever you'd like the application to "break" - that is, executing byebug is equivalent to putting a breakpoint in your code. Run the program and use the debugger commands once you reach the breakpoint. near the end. Restart your server.

What is Byebug in Ruby?

Byebug is a simple to use and feature rich debugger for Ruby. It uses the TracePoint API for execution control and the Debug Inspector API for call stack navigation.

What is Rails Byebug?

Rails 5 introduced byebug which is an easy-to-use, feature-rich ruby debugger. It offers features like Stepping, Breaking, Evaluating, Tracking. Using byebug we can easily control the execution of a program and the debug inspector for call stack navigation. This allows us to handle and track the execution flow.

How do you go to the next line in a Byebug?

Using “Next” If you use next , you won't go deep inside the calls. Instead, byebug will go to the next line within the same context. In this case, it is the last line of the current method, so byebug will return to the next line of the caller method.


2 Answers

So I found this question on Stackoverflow Byebug fully supports Windows or not? that was posted in Jan 2017.

I followed the issues on Github and found a commit in rails (sorry my network blocks github so can't like to them). the mri platform is not supported on windows and rails Gemfile generator template has now been updated to.

gem 'byebug', platform: [:mri, :mingw, :x64_mingw]

I made the change then ran my code and byebug now works on windows!

Might need to run bundle after the change.

like image 197
Jay Killeen Avatar answered Sep 17 '22 00:09

Jay Killeen


Works fine for one of my apps. I'm using pry as my default debugging tool and just dropping byebug in worked flawlessly.

  [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)

So, I think we need more code. Maybe your article params?

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
like image 42
Vlad Avatar answered Sep 20 '22 00:09

Vlad