我正在使用Rails 4.0,并试图获得以下路由:Rails 4.0 config/routes.rb问题想要:http:// localhost/api/v1 /:controller /:id
class Api::V1::MyController
def get # maps to http GET
end
def post # maps to http POST
end
... Same for PATCH PUT DELETE
end
我找不出正确的routes.rb。
我尝试几种变化:
namespace :api do
namespace :v1 do
match ':controller(/:action(/:id))', via: [:get, :put, :post, :patch, :delete]
end
end
结果错误:
和
match '/api/v1/:controller(/:action(/:id))', via: [:get, :put, :post, :patch, :delete]
结果错误 “控制器段是不是一个命名空间块内允许”:“在自动加载常量时检测到循环依赖性ApiController“
T他是我想的网址是什么样子:
http://www.localhost.com/api/v1/my_controller/1234
or eventually:
http://www.localhost.com/api/v1/photos/1234
http://www.localhost.com/api/v1/users1234
http://www.localhost.com/api/v1/albums/1234
http://www.localhost.com/api/v1/puppies/1234
你想让url看起来像什么? – dax
@dax重新解决了一个问题,我已经更新了它 - ty – Daniel