0

我将 JSON 作为 POST 发送到 Heroku 服务器上的 ruby​​ 应用程序(来自 Android 应用程序)。正如帖子标题所说,Heroku 日志输出:

Started GET "/app_session" for 62.40.34.220 at 2013-05-20 22:12:22 +0000
ActionController::RoutingError (No route matches [GET] "/app_session"):

这是安卓请求:

HttpPost httppost = new HttpPost(url.toString());
                    httppost.setHeader("Content-type", "application/json");
                    httppost.setHeader("Accept", "application/json");

                    StringEntity se = new StringEntity(json.toString());
                    httppost.setEntity(se);
                    HttpResponse response = httpclient.execute(httppost);

                    String temp = EntityUtils.toString(response.getEntity());
                    jsonResponse = new JSONObject(temp);

这是路由文件:

resources :app_session, only: [:create, :destroy]

rake routes输出:

app_session_index POST   /app_session(.:format)         app_session#create
      app_session DELETE /app_session/:id(.:format)     app_session#destroy

这里发生了什么?为什么要_index添加到app_session?肯定是这个问题...

4

1 回答 1

2

这是因为您的资源不是复数。有关更多信息,请参见Rails 3 route appends _index to route name

如果您将路线更改为:

resources :app_sessions, only: [:create, :destroy]

于 2013-05-20T22:38:33.867 回答