My First Rails Debugging Session

This morning students were given the task to debug an app built in Rails.

The app was not saving the created entries to the database and we needed to figure out why.

Well, I had an idea about it as I had previously discussed a similar problem with my smart classmate Sara. My hunch was that something was amiss when the controller told the database to save the entry.

This is how I solved the issue:

Once I cloned the app, I ran


rake db:migrate

in the command line to initialize the database. And bundled installed the gem ‘debugger’ in my Gemfile because I would need it.

Then I went to the controller, looked for the create method and inserted a debugger there.


 def create
    debugger
    @game = Game.new(params[:games])
    if @game.save
      redirect_to @game
    end
  end

I booted up the app by typing “rails server” in the command line and went on to create an new game in the application. Once debugger was prompted, I typed “params” to see if the game I had created had been added to a hash, and this what I got.


"game"=>{"name"=>" Super Mario Bros."}

Voilá, it was a pluralization issue because in the create method, we have


@game = Game.new(params[:games])

but that “[:games]” should be singular, i.e. “[:game]”.

So I made the corrections:


 def create
    @game = Game.new(params[:game])
    if @game.save
      redirect_to @game
    end
  end

And it worked! My first rails debug. Very proud.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s