0

我正在尝试更改 api 端点的 url 路径,因为 ember 应用程序正在连接到外部 api。

在本地,我的 ember 应用程序位于 localhost,而 api 位于 localhost:3000。

如果我尝试以下操作:

DS.RESTAdapter.reopen
  namespace: "api"
  url: "http://localhost:3003"

然后我单击一个linkTo helper,我收到以下错误:

No route matches [GET] "/api/tasks

如何让它绕过 localhost:3000 上提供的 Rails 路由直接进入 api 服务器?所以它应该请求localhost:3003/api/tasks而不是localhost:3000/api/tasks

4

2 回答 2

0

您的问题与 ember 路由无关,而是与 rails 路由有关。您需要使用namespace为您的资源在routes.rb. 如下所示:

namespace :api do
  resources :tasks
end

我希望它有帮助

于 2013-09-25T00:24:49.507 回答
0

您应该在 上设置host, 而不是url属性RESTAdapter。例如:

DS.RESTAdapter.reopen
  namespace: "api"
  host: "http://localhost:3003"

请参阅API 参考

于 2013-09-25T17:35:41.613 回答