#243 √ resolved
Jaroslaw Zabiello

Make merb.show_routes is broken

Reported by Jaroslaw Zabiello | April 2nd, 2008 @ 07:11 PM | in 0.9.4

merb -i; merb.show_routes looks very bad. It does not contain information about actions and controllers assigned to specific url. Output formating is also poor comparing to Rails. I think this should be refactored and added to rake tasks.

Comments and changes to this ticket

  • Jaroslaw Zabiello

    Jaroslaw Zabiello April 2nd, 2008 @ 07:17 PM

    It is difficult to make a patch because show_routes() is based on Merb::Router.named_routes which does not contain name of controller and action assigned to specific url. It does not contain HTTP action either.

  • Jaroslaw Zabiello

    Jaroslaw Zabiello April 2nd, 2008 @ 07:17 PM

    I meant: HTTP method, not action.

  • Michael Klishin (antares)

    Michael Klishin (antares) May 2nd, 2008 @ 09:25 AM

    • → Milestone changed from “” to “0.9.4”

    Any suggestions on this, Jaroslaw?

  • Jaroslaw Zabiello

    Jaroslaw Zabiello May 2nd, 2008 @ 11:23 AM

    I think Rails' "rake routes" displays all routes in very clean way. It shows HTTP methods related to controller and action. Compare (for resources :products)

    Merb:

    Named Routes
      delete_post: /posts/:id/delete
      new_post: /posts/new
      posts: /posts
      edit_post: /posts/:id/edit
      post: /posts/:id
    Anonymous Routes
      /posts/?(\.:format)?
      /posts/index(\.:format)?
      /posts/new
      /posts/?(\.:format)?
      /posts/:id(\.:format)?
      /posts/:id[;/]edit
      /posts/:id[;/]delete
      /posts/:id(\.:format)?
      /posts/:id(\.:format)?
      /:controller(/:action(/:id)?)?(\.:format)?
    

    Rails

                  products GET    /products                        {:action=>"index", :controller=>"products"}
        formatted_products GET    /products.:format                {:action=>"index", :controller=>"products"}
                           POST   /products                        {:action=>"create", :controller=>"products"}
                           POST   /products.:format                {:action=>"create", :controller=>"products"}
               new_product GET    /products/new                    {:action=>"new", :controller=>"products"}
     formatted_new_product GET    /products/new.:format            {:action=>"new", :controller=>"products"}
              edit_product GET    /products/:id/edit               {:action=>"edit", :controller=>"products"}
    formatted_edit_product GET    /products/:id/edit.:format       {:action=>"edit", :controller=>"products"}
                   product GET    /products/:id                    {:action=>"show", :controller=>"products"}
         formatted_product GET    /products/:id.:format            {:action=>"show", :controller=>"products"}
                           PUT    /products/:id                    {:action=>"update", :controller=>"products"}
                           PUT    /products/:id.:format            {:action=>"update", :controller=>"products"}
                           DELETE /products/:id                    {:action=>"destroy", :controller=>"products"}
                           DELETE /products/:id.:format            {:action=>"destroy", :controller=>"products"}
                                  /:controller/:action/:id         
                                  /:controller/:action/:id.:format 
    
  • Michael Klishin (antares)

    Michael Klishin (antares) May 4th, 2008 @ 10:56 AM

    • → Assigned user changed from “” to “Michael Klishin (antares)”

    Thanks for reply, will spend some time on it as I go through router code next time.

  • Michael Klishin (antares)

    Michael Klishin (antares) May 16th, 2008 @ 12:36 AM

    • → State changed from “new” to “open”

    Will spend some time on this, should be a good complement to #305 and #321.

  • Michael Klishin (antares)

    Michael Klishin (antares) May 17th, 2008 @ 06:32 PM

    • → State changed from “open” to “resolved”
    • → Title changed from “merb.show_routes is very poor” to “Make merb.show_routes format output better”

    You can find show_routes method in lib/merb-core/rack/adapter/irb.rb.

    Merb uses regexps heavily so even to get http method condition I had to do little tricks. It is a bit more verbose now but still far from perfect.

    Also I had tough time trying to make sprintf work with runner adapter (irb). So if you want it look exactly like Rails routes, or use Rake task for it, submit a patch and reopen this ticket.

  • Jaroslaw Zabiello

    Jaroslaw Zabiello May 17th, 2008 @ 09:19 PM

    merb.show_routes works wrong. It displays incorrect HTTP methods. For resource :products I get

    {{{

    Helper : product

    HTTP method: GET

    Route : /products/:id

    Params : {:action=>"\"index\"", :id=>"path1"}

    Helper : new_product

    HTTP method: GET

    Route : /products/new

    Params : {:action=>"\"index\""}

    Helper : edit_product

    HTTP method: GET

    Route : /products/:id/edit

    Params : {:action=>"\"index\"", :id=>"path1"}

    Helper : delete_product

    HTTP method: GET

    Route : /products/:id/delete

    Params : {:action=>"\"index\"", :id=>"path1"}

    ....

    }}}

    It makes no sense. new, edit or delete product should use POST, PUT and DELETE methods, not GET! And not index action either.

  • Jaroslaw Zabiello

    Jaroslaw Zabiello May 17th, 2008 @ 09:22 PM

    Argh... how to reopen this ticket??

  • Jaroslaw Zabiello

    Jaroslaw Zabiello May 17th, 2008 @ 09:22 PM

    • → Title changed from “Make merb.show_routes format output better” to “Make merb.show_routes is broken”
  • Michael Klishin (antares)

    Michael Klishin (antares) May 17th, 2008 @ 09:24 PM

    • → State changed from “resolved” to “open”

    I think only account members can re-open tickets, so I did. If you think it is *broken*, fix it and make patches with git-format-patch. Thanks.

  • Jaroslaw Zabiello

    Jaroslaw Zabiello May 17th, 2008 @ 09:49 PM

    Michael, the problem is deeper than I thought. Look:

    Helper     : new_product
    HTTP method: GET
    Route      : /products/new
    Params     : {:action=>"\"index\""}
    

    The action should be 'create', not 'index'. This is apparent error. And this error must lay somewhere inside merb-core/dispatch/route.rb code (because this error is already existing in Merb::Router.named_routes).

    Routes' code is not simple. It would be better to assign this ticket to the person who have created this class. Ezra?

  • Jaroslaw Zabiello

    Jaroslaw Zabiello May 17th, 2008 @ 09:51 PM

    er, action should be 'new', not 'create', nor 'index'

  • Michael Klishin (antares)

    Michael Klishin (antares) May 17th, 2008 @ 10:23 PM

    There is plenty of specs for router, please write one to prove that something is broken before making judgements. Also, to understand router it took me just two days. Try it, and you will learn a lot.

  • Michael Klishin (antares)

    Michael Klishin (antares) May 17th, 2008 @ 10:38 PM

    I double checked resources specs, nothing looks wrong. So a spec example that proves problem would be great.

  • Star Trader

    Star Trader May 18th, 2008 @ 12:07 AM

    Jaroslaw Zabiello:

    Recent changes I made (ticket #324) make the default action "index" a bit sticker, and it is now showing up in odd places.

    There is problem here, but it's not what you think. Before I go any farther with an explanation, lets get some common ground:

    # > merb -i
    Merb::Router.prepair do |r|
      r.resources :products
    end
    merb.show_routes
    

    The resources call does a lot of magic behind the scenes, as merb.show_routes demonstrates. One of the problems it that one cannot name a route that uses a regexp. In order to add the optional format parameter at the end All the resources routes are defined by a regexp. In order to name them properly, fake routes are created with strings that are designed to match the regexp. These routes lead to nowhere and in fact will never be routed because the anonymous routes will fire first. (See my post, Merb: Routing 201 )

    Having said this, the output of merb.show_routes is rather deceptive. For resources named routes are used in #url only, but nothing tells us that. I'm not sure how to resolve this as we have "lost" information about which named route is responsible for generating a url that will trigger a spesified anonymous route.

    A solution to this problem would most likely also resolve the issue of not being able to name regexp routes. In the mean time, I think it might be a good idea to have show routes list it's routes in the order they are evaluated. The possibility that routes contain regexp's and deferred blocks makes displaying routes much harder then in rails.

  • Michael Klishin (antares)

    Michael Klishin (antares) June 25th, 2008 @ 01:17 AM

    • → State changed from “open” to “resolved”

    After long discussions nobody really stepped up to do something beyond what we have. I will close this one. Feel free to reopen when you have some working prototype.

    I do understand that show_routes is poor but looks like nobody really cares enough to hack on Merb's router to reverse regexp routes information into human readable form.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »