Search code examples
ruby-on-rails-3routesruby-on-rails-3.2rails-cells

A custom route is matched in development but results in 404, in production


I have a following definition in my routes.rb

  match "/block/:name/:action" => proc { |env|
    #heavy magic happens here
  }

I use it for handling rendering of cells. My problem is that the following link:

/block/reporting%2Fother%2Fexample/new?exampleable_id=23736&exampleable_type=Abc%3A%3ASomeType

works perfectly fine in development mode, but in production I get "404 Not Found". The only difference between production and development urls is that the one in development uses http and the one in production uses https. I would understand if I wrote a faulty code my proc block, but for the love of god I can't understand why it is not matched in production environment, when it works perfectly fine in development.

Any hint on how to debug this is highly appreciated. There is not so much hair left on my head.


Solution

  • I got this error even when if I finally launched the project in production environment on my local machine. The thing is we do not use Thin in production. We use passenger. After I finally got passenger working locally, I managed to recreate the error.

    It turned out that with passenger, the :name in aforementioned route wasn't interpreted as "reporting%2Fother%2Fexample", but possibly as /block/reporting/other/example/new" with the rest not matched, of course.

    I fixed the error by replacing

    match "/block/:name/:action"
    

    to

    match "/block/*name/:action"
    

    I hope this answer to my own question helps someone in the future.