Sinatra & Rails 3 routes issue

2019-08-20 07:20发布

I have just setup Sinatra v1.1.0 inside my rails (v3.0.1) app. But I can't invoke any routes that are more than 1 level deep, meaning this works - http://localhost/customer/3,

but this one does not work - http://localhost/customer/3/edit and I get a "Routing Error"

Here's the Sinatra object

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

This is what I have in my rails routes.rb file -

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

I am guessing I need some magic in the routes file? What could be the problem?

2条回答
We Are One
2楼-- · 2019-08-20 07:37

In your routes file, you can specify the mapping this way:

mount CustomerApp, :at => '/customer'

Now, inside your sinatra application, you can specify your routes without the /customer part. Dont't forget to require your sinatra application somewhere (you can do it directly in the route file)

查看更多
We Are One
3楼-- · 2019-08-20 07:47

You need to add an additional route to match the different URL:

match '/customer/(:string)/edit' => CustomerApp
查看更多
登录 后发表回答