Rails 自定义路线映射不正确
Rails custom route does not map correctly
我正在向另一个控制器发出 ajax 请求,但路由有问题。这是我的要求:(使用 react.js)
$.ajax({
type: 'GET',
url: 'allRooms',
dataType: 'json',
success:function(data){
this.setState({data:data});
}.bind(this)
});
我把这个放在我的 routes.rb:
get 'allRooms', to: 'rooms#allRooms'
现在,allRooms
是我在 rooms_controller
中定义的方法
但是,请求在触发时得到此 url:http://localhost:3000/houses/allRooms
调用是从我家主控的show-view中进行的。
为什么我的请求没有正确路由到客房控制器? (我多次重启 rails 服务器)
$.ajax({
type: 'GET',
url: 'http://localhost:3000/allRooms',
dataType: 'json',
success:function(data){
this.setState({data:data});
}.bind(this)
});
尝试将您的 js 代码更改为:
$.ajax({
type: 'GET',
url: '/allRooms',
dataType: 'json',
success:function(data){
this.setState({data:data});
}.bind(this)
});
我正在向另一个控制器发出 ajax 请求,但路由有问题。这是我的要求:(使用 react.js)
$.ajax({
type: 'GET',
url: 'allRooms',
dataType: 'json',
success:function(data){
this.setState({data:data});
}.bind(this)
});
我把这个放在我的 routes.rb:
get 'allRooms', to: 'rooms#allRooms'
现在,allRooms
是我在 rooms_controller
但是,请求在触发时得到此 url:http://localhost:3000/houses/allRooms
调用是从我家主控的show-view中进行的。
为什么我的请求没有正确路由到客房控制器? (我多次重启 rails 服务器)
$.ajax({
type: 'GET',
url: 'http://localhost:3000/allRooms',
dataType: 'json',
success:function(data){
this.setState({data:data});
}.bind(this)
});
尝试将您的 js 代码更改为:
$.ajax({
type: 'GET',
url: '/allRooms',
dataType: 'json',
success:function(data){
this.setState({data:data});
}.bind(this)
});