我将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
?
当然这就是问题......
答案 0 :(得分:2)
这是因为你的资源不是复数。有关详情,请参阅Rails 3 route appends _index to route name。
如果您将路线更改为:
,您应该很高兴 resources :app_sessions, only: [:create, :destroy]