路由存在的原因可以视为没有路由匹配(RoutingError)
Why does the route exist can be regarded as no route matches(RoutingError)?
rails服务器显示
Started POST "/user/1/follow"
ActionController::RoutingError (No route matches [POST] "/user/1/follow"):
但是使用rake routes
Prefix Verb URI Pattern Controller#Action
followers_user GET /users/:id/followers(.:format) users#followers
followings_user GET /users/:id/followings(.:format) users#followings
follow_user POST /users/:id/follow(.:format) users#follow
基于以上信息,我不知道为什么路由存在可以被视为没有路由匹配(RoutingError)。看来这条路线确实存在。
下面是可能与这个问题相关的其他信息。我使用jquery通过
触发路由 $.ajax({
url: '/user/'+userId+'/follow',
type: 'POST',
});
users#follow被定义为
def follow
if current_user?(@user)
flash[:error] = "You cannot follow yourself"
elsif current_user.following?(@user)
flash[:error] = "You already follow #{@user.name}"
end
if request.xhr?
render status: current_user.follow(@user) ? 200 : 400, nothing: true
end
end
你已经将你的路由定义为
follow_user POST /users/:id/follow(.:format) users#follow
但是在jQuery代码片段中,你使用/user/...
而不是/users/...
你的路由路径在jquery帖子中是不同的,正确的路由'users/1/follow'
,我在我的工作中使用的一个超级技巧,使用gem js-routes,它提供了在javascript中访问的路由路径。
希望这对你有帮助
相关文章:
- Emberjs应用程序加载在除Index之外的所有路由上
- 正在使用$location.path(.)路由ng视图
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- 未激发路由的控制器属性上的观察者
- AngularJS ui路由器html5模式中断路由
- 发送json对象或使用express路由呈现视图
- 使用主干网和rails的静态页面路由
- 如何使用Passport保护路由终结点
- 有没有办法用routerLink/router.navigation附加查询/路由参数
- Nodejs和express路由,如何处理客户端的承诺
- TinyMCE实例在切换角度路由选项时会消失
- 什么'在Express中路由时,应用程序级中间件和路由器级中间件之间的区别是什么
- 使用Ampersand.js路由模块化应用程序
- Angular 2路由已弃用:如何检测CanActivate
- 格式化获取请求的路由
- 在node-js路由中发出http请求
- 无法运行php代码,有角度路由问题
- 更改路由后,运行一次js脚本
- 路由存在的原因可以视为没有路由匹配(RoutingError)
- RoutingError(没有与[OPTIONS]匹配的路由