It seems to me that the problem is that Rails.application.routes.named_routes.routes is a Hash and so no order is implied. Would it be reasonable to sort this, e.g. in alphabetical order by key name, when it is needed?
Yes, seems reasonable.
Btw are you using 1.8 or 1.9? This can make a big difference in how Hash works.
So, all you need is add sort call at this line:
js_routes = Rails.application.routes.named_routes.routes.sort.map do |_, route|
I don't want to commit this to master until make sure it fixes your problem
Please try it on your side