2010-11-16 73 views
0

我刚刚在我的rails(v3.0.1)应用程序中设置了Sinatra v1.1.0。但我不能调用是超过1级深的任何路由,这意味着该工程 - http://localhost/customer/3Sinatra&Rails 3 routes issue

但是这一次不工作 - http://localhost/customer/3/edit,我得到一个“路由错误”

这里的西纳特拉对象

class CustomerApp < Sinatra::Base 

    # this works 
    get "/customer/:id" do 
    "Hello Customer" 
    end 

    # this does NOT work 
    get "/customer/:id/edit" do 
    "Hello Customer" 
    end 

end 

这是我在轨routes.rb中文件 -

match '/customer/(:string)' => CustomerApp 

我猜我需要在航线网络的一些魔术乐?可能是什么问题呢?

+0

routes.rb文件中有大量的例子被注释掉了。 – rwilliams 2010-11-16 07:25:22

回答

1

您需要添加额外的途径来匹配不同的URL:

match '/customer/(:string)/edit' => CustomerApp 
+0

非常感谢,这意味着你需要重复的网址,这不是很好。 – kapso 2010-11-17 23:27:25

3

在你的路由文件,你可以指定映射是这样的:

mount CustomerApp, :at => '/customer' 

现在,您的西纳特拉的应用程序中,您可以在没有/customer部分的情况下指定您的路线。 不要忘记要求你的sinatra应用程序在某处(你可以直接在路径文件中执行)