5

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?

sam0101
  • 373
  • 1
  • 4
  • 15
  • can you put the whole code of the controller? – Milan Pudasaini Jun 15 '16 at 12:39
  • Milan Pudasini .. I updated it you can see my whole code of my conroller.. – sam0101 Jun 15 '16 at 12:51
  • remove debugger once and put byebug on that place – Mukesh Jun 15 '16 at 13:10
  • Tried it but did not work also.. – sam0101 Jun 15 '16 at 13:25
  • 1
    I suggest not using Windows to develop a Rails application. The Ruby CLI, Rails CLI, Git CLI and general deployment process is much better in a Linux based terminal/environment. If that's the only PC you have, I'd install Ubuntu with VirtualBox and use that instead. –  Jun 15 '16 at 14:02
  • @Meshpi what he said! I don't know why people develop on Windows when it's so easy to setup a VB. – Vlad Jun 15 '16 at 14:05
  • Yes it is the only laptop i have...I know that in mac is better than windows and a lot of people recomend me not using windows with rails.. but I can not afford buying a mac at this point...do it will take a lot of time to install unbunto with virtualBox?? and would it make my laptop slower?? – sam0101 Jun 15 '16 at 14:17
  • @sam0101 depends on what resources your machine has. Having VirtualBox is like having 2 OS's on the same machine. Although you can define what resources should VB take, it will slow it, but not considerably. As for installing it, no, not really. There are loads of images of Ubuntu ready to install, setup specially for Rails development https://github.com/rails/rails-dev-box – Vlad Jun 15 '16 at 14:34
  • ty for that..will try it – sam0101 Jun 15 '16 at 14:36
  • hey @sam0101 looks like your controller is fine, can i see the code in the view.. a form, thanks – Milan Pudasaini Jun 16 '16 at 05:35
  • 1
    Hi @MilanPudasini I solved it by moving to ubuntu like they told me above...thank you anyway ;) – sam0101 Jun 16 '16 at 17:18

2 Answers2

4

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.

Community
  • 1
  • 1
Jay Killeen
  • 2,832
  • 6
  • 39
  • 66
  • The next step is to get irb working in Git Bash because that is stopping `byebug` from working correctly. Refer to this question if you have an `Switch to inspect mode.` in your `rails console` output. http://stackoverflow.com/questions/38132561/how-to-get-irb-and-rails-console-to-work-properly-in-gitbash – Jay Killeen May 14 '17 at 23:44
1

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
Vlad
  • 902
  • 4
  • 14
  • I have no idea what's wrong with your code. It looks fine from my POV. I think your problem lies somewhere else. Have you tried `pry` instead of `byebug` ? – Vlad Jun 15 '16 at 14:04
  • no i didnt...is it a gem??can you provide me with the link please? – sam0101 Jun 15 '16 at 14:15
  • https://github.com/pry/pry .. in your file do `require 'pry'` at the top of the class and then replace `debugger` with `binding.pry` . – Vlad Jun 15 '16 at 14:32
  • Thanks..wil try it – sam0101 Jun 15 '16 at 14:36
  • How did you go @sam0101? I have the same issue. I think it might be a problem with Git Bash. – Jay Killeen Aug 21 '16 at 23:15
  • 1
    @JayKilleen Yes I moved to ubuntu and it solved my problem...The problem is I was working on windows and that comes with a lot of problems – sam0101 Aug 22 '16 at 22:23
  • Thanks @sam0101. I am using Windows too although have the new Bash for Ubuntu on Windows installed. Might give it a try on that and see if I still have the same problem. – Jay Killeen Aug 22 '16 at 23:09
  • You are welcome...There is lot of developers recommended not to use windows for rails, For me working on windows comes with lot of problems so I suggest u to give ubuntu a try..;) – sam0101 Aug 23 '16 at 16:13
  • Here we go again with the same problem 9 months later... rails development on windows is still a whole heap of fail. Can't even use `rails console` in Git Bash without issues. If anyone has figured this out please comment or answer. – Jay Killeen May 14 '17 at 23:22
  • Whoop fixed it. Followed http://stackoverflow.com/questions/41674136/byebug-fully-supports-windows-or-not I'll post a new answer. – Jay Killeen May 14 '17 at 23:34