我正在使用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