Devise Overriding Controller Route - Ruby on Rails

ErrorsRuby on RailsWeb Development

I ran into a bit of a problem today after implementing a search form that appeared on every page. When the login page was loaded I received the following error:

No route matches {:controller=>”devise/products”, :method=>:get, :action=>”search”}

The weird thing about this is that the route my search form uses does not mention devise in any way:

 'products', :action => 'search', :method => :get do %>

As you have probably already guessed, I’m using devise to handle my authentication. Unfortunately this seems to be overriding some of my routes whenever it co-exists with another form. Luckily there exists a very simple, although hard to find solution – simply add a forward slash before the controller definition:

 '/products', :action => 'search', :method => :get do %>

Here’s a quick link to the StackOverflow post which gave the answer, hopefully a few more links to it will make it a little easier to find for anyone else out there doing a search!

4 comments

Comments from the original blog are preserved here. New comments are closed.

  1. Olivier

    Man, your stuff about the "/" in front of the controller saved my day !! ...

    Thanks a lot for posting this !

  2. Errors
    In reply to Olivier

    No worries, thanks for the feedback!

  3. Simon

    Thanks so much for this! This seems like some strange behaviour. Do you know if this problem persists in Rails 4?

  4. Chris Owens
    In reply to Simon

    Hey Simon,

    No worries, and sorry not too sure about Rails 4.

    Cheers,
    Chris