Carles Andrés

Passionate Web Developer

Debugging Rails Routes Issues

Yesterday I had to debug a very silly error in Rails while developing a feature for Typo. The error message was:

Unknown action
The action 'merge' could not be found for Admin::ContentController

Of course, I was pretty sure I had done everything right but, I couldn’t just ignore it.

At first, I thought it might be an error in my routing configuration, although this was not what the error message said (Stupid me). However, I wanted to make sure there was no subtle routing problem I wasn’t aware of.

First, I used Chrome Developer Tools to inspect the Http request and everything I found seemed ok.

Then I did some research so as to further inspect the call to the failing action’s route. I discovered I could open a rails console from within my app folder:

rails console

And from there I could very easily create a handy routes object:

r = Rails.application.routes

Which I could use to check if my route pointed to the proper controller and method:

r.recognize_path "/admin/content/merge/3", :method => :get

That gave the following result:

=> {:action=>"merge", :id=>"3", :controller=>"admin/content"}

Which, as you probably already know, means it will look for method merge, inside:



params[:id] = 3

So there was no routing problem and I just couldn’t figure out where the problem was.

At last, I opened content_controller.rb in Sublime Text 2 (instead of my usual text editor, VIM) and found a second copy of my merge method in a very different place inside the same file. I can swear I don’t know how it got there.

…Anyway!. I deleted the wrong copy of the method and everything worked right. My Cucumber and RSpec didn’t complain about it and I felt, again, like a superhero.

I really never though that a duplicate name for a method could make Ruby issue an “Unknown action” error, but that’s exactly what happened to me.