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"):

これは Android リクエストです。

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 に答える